I have used this
public List<InspectionReport> GetInspectionReportDetails(int InspectionReportID)
{
var List= this.Database.SqlQuery<InspectionReport>("GetInspectionReportDetails", InspectionReportID).ToList();
return List;
}
in a class that is inherited from DbContext
I am calling this function in a controller but List is empty. Database.SqlQuery returns 0 items even the procedure is returning data for the parameter i am providing to the function but not this.
Update:
alter PROCEDURE GetInspectionReportDetails
#InspectionReportID int=0
AS
BEGIN
Select ir.InspectionReportID
,ir.VelosiProjectNo
,ir.VelosiReportNo
,ir.Reference
,ir.PoNo
,ir.InspectionDate
,ir.IssueDate
,ir.InspectionPhase
,ir.InServiceInspection
,ir.NewInduction
,ir.HydrostaticTest
,ir.DimensionalCheck
,ir.ThicknessCheck
,ir.Patrom
,ir.Gvs
,ir.FinalOgraInspection
,ir.OmcClientRequirement
,ir.TankLorryRegistrationNo
,ir.TruckTractorManufacturerName
,ir.ClientName
,ir.Capacity
,ir.Omc
,ir.EngineNo
,ir.TankLorryDimension
,ir.ChassisNo
,ir.InspectionPlace
,ir.TankLorryEnginePower
,ir.CarriageName
,ir.Brakes
,ir.IsSatisfactory
,ir.Remarks
,ir.Rev
,ir.Description
,ir.Status
,u1.UserName as PeparedBy
,u2.UserName as CheckedBy
,u3.UserName as ApprovedBy
,u4.UserName as IssuedBy
From InspectionReport ir
Inner Join dbo.[User] u1
ON u1.UserID= ir.PeparedBy
Inner Join dbo.[User] u2
ON u2.UserID= ir.CheckedBy
Inner Join dbo.[User] u3
ON u3.UserID= ir.ApprovedBy
Inner Join dbo.[User] u4
ON u4.UserID= ir.IssuedBy
where ir.InspectionReportID= #InspectionReportID
This is the stored procedure that is called by the function.
This the class inpsectionreport;
namespace VAILCertificates.DAL.Entities
{
public class InspectionReport
{
//General Details
public int InspectionReportID { get; set; }
[Required]
[Display (Name= "Velosi Project No")]
public string VelosiProjectNo { get; set; }
[Display(Name = "Velosi Report No")]
public string VelosiReportNo { get; set; }
[Required]
public string Reference { get; set; }
[Required]
[Display(Name = "PO No")]
public string PoNo { get; set; }
[Required]
[Display(Name = "Inspection Date")]
public DateTime InspectionDate { get; set; }
[Required]
[Display(Name = "Issue Date")]
public DateTime IssueDate { get; set; }
//Inspection Phase
[Required]
[Display(Name = "Inspection Phase")]
public byte InspectionPhase { get; set; } //0= Before, 1= During, 2= Final
//Types Of Inspection
[Display(Name = "In Service Inspection")]
public bool InServiceInspection { get; set; }
[Display(Name = "New Induction")]
public bool NewInduction { get; set; }
[Display(Name = "Hydorstatic Test")]
public bool HydrostaticTest { get; set; }
[Display(Name = "Dimensional Check")]
public bool DimensionalCheck { get; set; }
[Display(Name = "Thickness Check")]
public bool ThicknessCheck { get; set; }
[Display(Name = "PATROM")]
public bool Patrom { get; set; }
[Display(Name = "GVS")]
public bool Gvs { get; set; }
[Display(Name = "Final OGRA Inspection")]
public bool FinalOgraInspection { get; set; }
[Display(Name = "OMC/Client Requirement")]
public bool OmcClientRequirement { get; set; }
//Details Of Tank Lorry
[Required]
[Display(Name = "Tank Lorry Registration Number")]
public string TankLorryRegistrationNo { get; set; }
[Required]
[Display(Name = "Truck Tractor Manufacturer Name")]
public string TruckTractorManufacturerName { get; set; }
[Required]
[Display(Name = "Client Name")]
public string ClientName { get; set; }
[Required]
[Display(Name = "Capacity")]
public string Capacity { get; set; }
[Required]
[Display(Name = "OMC")]
public string Omc { get; set; }
[Required]
[Display(Name = "Engine No")]
public string EngineNo { get; set; }
[Required]
[Display(Name = "Tank Lorry Dimension")]
public string TankLorryDimension { get; set; }
[Required]
[Display(Name = "Chassis Number")]
public string ChassisNo { get; set; }
[Required]
[Display(Name = "Inspection Place")]
public string InspectionPlace { get; set; }
[Required]
[Display(Name = "Tank Lorry (Engine Power)")]
public string TankLorryEnginePower { get; set; }
[Required]
[Display(Name = "Carriage Name")]
public string CarriageName { get; set; }
[Required]
public string Brakes { get; set; }
//ResultsofInspection
[Required]
[Display(Name = "Is Satisfactory?")]
public bool IsSatisfactory { get; set; }
//Remarks
[Required]
public string Remarks { get; set; }
//ApprovalSection
public string Rev { get; set; }
[Required]
public string Description { get; set; }
[Required]
public int PeparedBy { get; set; }
public int CheckedBy { get; set; }
public int ApprovedBy { get; set; }
public int IssuedBy { get; set; }
//ReportStatus
public byte Status { get; set; } //0= Prepared 1= CheckedBy 2= ApprovedBy
}
}
You can also construct a DbParameter and supply it as a parameter value to your stored procedure:
var InspectionReportID= new SqlParameter("#InspectionReportID", 0);
var list = this.Database.SqlQuery<InspectionReport>("EXECUTE dbo.GetInspectionReportDetails #InspectionReportID",InspectionReportID).ToList();
It is important to parameterize any user input to protect against a SQL injection attack. You can include parameter placeholders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter.
Try changing the the sql statement, I feel the error is how you call the sql statement.
var list = this.Database.SqlQuery<InspectionReport>($"EXEC GetInspectionReportDetails {InspectionReportID}").ToList();
Try using this code:
public List<InspectionReport> GetInspectionReportDetails(int InspectionReportID)
{
var List= this.Database.SqlQuery<InspectionReport>("GetInspectionReportDetails #InspectionReportID", InspectionReportID).ToList();
return List;
}
Related
Currently i have the following structure of my classes:
public class StoreElement
{
[Display(Name="ID")]
public int StoreElementId { get; set; }
[Display(Name = "RegalID")]
public string StoreElementCode { get; set; }
[Display(Name = "Regal")]
public string Storage { get; set; }
[Display(Name="Ebene")]
public string Level { get; set; }
[Display(Name = "Fach")]
public string Shelf { get; set; }
[Display(Name = "ESL Tag")]
public string ESLTagId { get; set; }
[Display(Name ="ESL Layout Template")]
public string ESLLayoutValue { get; set; }
[Display(Name = "Eingelagertes Material")]
public List<Material> Materials { get; set; }
}
And this class:
public class Material
{
[Display(Name = "ID")]
public int MaterialId { get; set; }
[Display(Name = "Materialnummer")]
public int? MaterialNumber { get; set; }
[Display(Name = "Auftragsnummer")]
public int? OrderNumber { get; set; }
[Display(Name = "Eingelagert")]
public bool? IsStored { get; set; }
[Display(Name = "Einlagerdatum")]
public DateTime StoredAt { get; set; }
[Display(Name = "Auslagerdatum")]
public DateTime OutsourcedAt { get; set; }
[Display(Name = "Liefertermin")]
public DateTime DeliveryDate { get; set; }
[Display(Name = "Priorisiertes Material")]
public bool PriorityMaterial { get; set; }
public int? StoreElementId { get; set; }
public StoreElement StoreElement { get; set; }
}
A StoreElement can hold a List of Materials. The class Materials contains a property which is a date. Now i would like to order the Storage-Location List by the subproperty date of a list of materials.
I tried something in linq like that:
var myOrderdStorageLocationsByDeliveryDateOfMaterialsSublist = this.MyDatabaseContext.StorageLocations.Include(x=>x.Materials).OrderBy(x=>x.Materials.OrderBy(y=>y.DeliveryDate)).ToList();
But this throws an exception that says "Failed to compare two elements in the array"
Obviously, you need some value from Materials. And OrderBy won't return it.
I would recommend you to get a particular value for sorting StoreElements based on what logic you need: Min, Max or Average for example.
var myOrderdStorageLocationsByDeliveryDateOfMaterialsSublist = this.MyDatabaseContext.StorageLocations
.Include(x=>x.Materials)
.OrderBy(x=>x.Materials.Min(y=>y.DeliveryDate))
.ToList();
I have a ViewModel with several properties (VM for multi-step wizard):
public class CallViewModel
{
[Key]
[Column(Order = 0)]
[HiddenInput(DisplayValue = false)]
public System.Guid CallID { get; set; }
[Required, Display(Name = "Call Date")]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd MM yyyy} г.")]
public System.DateTime CallDate { get; set; }
[Required, Display(Name = "Contract Number")]
public string Number { get; set; }
[Display(Name = "Date of Sampling"), DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd MM yyyy} г.")]
public System.DateTime SampleActDate { get; set; }
[Display(Name = "Date of the Contract"), DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd MM yyyy} г.")]
public System.DateTime ContractDate { get; set; }
[Required, Display(Name = "Cost Efficiency, %")]
public decimal CostEfficiency { get; set; }
[Required, Display(Name = "Document Type")]
public string CallName { get; set; }
//Representative
[Required, Display(Name = "Second Name")]
public string RepFamilyName { get; set; }
[Required, Display(Name = "First Name")]
public string RepFirstName { get; set; }
[Required, Display(Name = "Middle Name")]
public string RepMidName { get; set; }
[Required, Display(Name = "Position")]
public string RepPosition { get; set; }
[Required, Display(Name = "Document")]
public string DocType { get; set; }
[Required, Display(Name = "Phone (###) ###-##-##")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:(###) ###-##-##}")]
public string RepPhoneNumber { get; set; }
//Customer
[Required, Display(Name = "Judicial Status")]
public string JudicialStatus { get; set; }
[Required, Display(Name = "Customer Name")]
public string CustomerName { get; set; }
[Required, Display(Name = "Address")]
public string CustomerAddress { get; set; }
[Required, Display(Name = "TaxID")]
public string TaxID { get; set; }
[Display(Name = "BIC")]
public string BIC { get; set; }
[Required, Display(Name = "PHone Number (###) ###-##-##")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:(###) ###-##-##}")]
public string CustomerPhoneNumber { get; set; }
[Required, Display(Name = "OKPO")]
public int OKPO { get; set; }
[Required, Display(Name = "Account)]
public string CustomerBankAccount { get; set; }
[Required, Display(Name = "Bank Branch")]
public string BankBranch { get; set; }
[Required, Display(Name = "Bank Address")]
public string BranchAddress { get; set; }
[Display(Name = "Bank Code")]
public Nullable<int> BankCode { get; set; }
[Display(Name = "Cell Phone Number")]
public string MPhoneNumber { get; set; }
//Person
[Required, Display(Name = "Expert")]
//public string Exp { get; set; }
public Guid ExpID { get; set; }
[Required, Display(Name = "Affidavit Number")]
public int AffidavitNum { get; set; }
[Required, Display(Name = "Affidavit Date"),
DataType(DataType.Date)]
public System.DateTime AffidavitDate { get; set; }
public List<ItemClass> ItemsList { get { return _items; } }
private List<ItemClass> _items = new List<ItemClass>();
public class ItemClass
{ //Item
public Guid ItemID { get; set; }
[Required, Display(Name = "Item SubType")]
public Guid ItemSubtype { get; set; }
[Required, Display(Name = "Item Name")]
public string ItemName { get; set; }
[Required, Display(Name = "Producer")]
public string ItemProducer { get; set; }
[Required, Display(Name = "Quantity")]
public int ItemQty { get; set; }
[Display(Name = "Additionals")]
public string Additional { get; set; }
[Required, Display(Name = "Program Name")]
public string ProgramNameShort { get; set; }
[Required, Display(Name = "Calc Date")]
public string calcDate { get; set; }
[Required, Display(Name = "Calc Number")]
public string calcNum { get; set; }
}
}
I also have several entities with 1:n relationships, like
public partial class Call
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Call()
{
this.CallDetails = new HashSet<CallDetail>();
}
public System.Guid CallID { get; set; }
public System.DateTime CallDate { get; set; }
public System.Guid CustomerID { get; set; }
public string DocNumber { get; set; }
public int AffidavitNum { get; set; }
public System.DateTime AffidavitDate { get; set; }
public System.DateTime ContractDate { get; set; }
public int CallStatus { get; set; }
public string DocType { get; set; }
public Nullable<decimal> Cost_Efficiency { get; set; }
public System.DateTime SampleActDate { get; set; }
public string CallName { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<CallDetail> CallDetails { get; set; }
public virtual Customer Customer { get; set; }
}
and
public partial class CallDetail
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public CallDetail()
{
this.Orders = new HashSet<Order>();
}
public System.Guid CallID { get; set; }
public System.Guid ItemID { get; set; }
public int ItemQty { get; set; }
public decimal ItemTestCost { get; set; }
public System.Guid ProgramID { get; set; }
public virtual Call Call { get; set; }
public virtual Item Item { get; set; }
public virtual Program Program { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Order> Orders { get; set; }
}
to name a few.
In [HttpPost] public ActionResult Create (CallViewModel callViewModel) method I should map the ViewModel to those entities. I know that Automapper is among the best ways to perform it, but still I need to understand the principles of correct mapping of VM and related entities (Automapper examples are welcome as well :) ), and especially how to deal with navigation properties (I'm mostly worried about ID properties). Could you please show the best (or template) practice to perform it? Please, be as detailed as possible.
Thanks in advance.
Take this example:
public class ModelClass
{
public Guid Id { get; set; }
public ChildModel ChildModel { get; set; }
}
public class ViewModelClass
{
public Guid Id { get; set; }
public ChildModel ChildModel { get; set; } = new ChildModel();
}
public class ChildModel
{
public Guid Id { get; set; }
}
If you want to map your viewmodel to your model you can do:
[HttpPost]
public ActionResult Create (CallViewModel callViewModel) {
var model = new ModelClass;
model.Id = callViewModel.Id;
model.ChildModel = callViewModel.ChildModel;
_context.Add(model);
_context.SaveChanges();
return RedirectToAction("Index");
}
For the use of automapper I suggest you read the AutoMapper docs :)
i have 3 models
public class UsersModel
{
[Key]
public int UserId { get; set; }
[Required]
[StringLength(100, ErrorMessage = "Invalid Name Minimum Length is 5", MinimumLength = 5)]
public string Name { get; set; }
//20150090
public int? student_ID { get; set; }
[Display(Name = "transcript")]
public string transcript { get; set; }
[Required]
[EmailAddress]
public string Email { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password do not match.")]
public string ConfirmPassword { get; set; }
[Required]
[StringLength(100, ErrorMessage = "Invalid Name Minimum Length is 2", MinimumLength = 2)]
public string Department { get; set; }
[Required]
[Display(Name = "Phone")]
[DataType(DataType.PhoneNumber,ErrorMessage ="Invalid Phone Number")]
[Range(999999999, 9999999999)]
public int Phone { get; set; }
public int type { get; set; }
}
student
public class StudentsModel
{
[Key]
[Display(Name ="ID")]
public int StudentID { get; set; }
[Required]
public string Name { get; set; }
[Required]//20150090
public string student_ID { get; set; }
[Required]
[Display(Name = "Skills")]
public string Skills { get; set; }
[Required]
[Display(Name = "Gpa")]
[Range(1.00, 4.00, ErrorMessage = "It must be in range 0.00 to 4.00 :)")]
public float Gpa { get; set; }
[Required]
[Display(Name = "Leader")]
public string Leader { get; set; }
[Required]
[Display(Name = "transcript")]
public string transcript { get; set; }
[ForeignKey("UserId")]
public int UserId;
public UsersModel Users { get; set; }
[ForeignKey("IdeaId")]
public int? IdeaId;
public IdeaModel Idea { get; set; }
}
Idea
public class IdeaModel
{
[Required]
[Key]
public int IdeaId { get; set; }
[Required]
public string IdeaName { get; set; }
[Required]
public string IdeaDescription { get; set; }
[Required]
public string tools { get; set; }
public int? SetWith { get; set; }
[Required]
public int Prof1 { get; set; }
public int Prof2 { get; set; }
public int Prof3 { get; set; }
}
when i insert to the database user and student and idea
the foreign key in student model inserted with null value
this is the code for insertion
i want the foreign key in student model to inserted automatically
whit the values of primary key in usernodel and idea model how to make this?
public ActionResult RegisterLeader(regall reg)
{
if (ModelState.IsValid)
{
var user= db.Users.Add(reg.users);
var idea = db.Idea.Add(reg.idea);
var stu = db.Students.Add(reg.students[0]);
db.SaveChanges();
return View("RegisterLeaderPost");
//return Registerfinish();
}
}
this model have the three models
public class regall
{
public List<StudentsModel> students { get; set; }
public UsersModel users { get; set; }
public IdeaModel idea { get; set; }
}
You need to set the Idea property of the student so EF knows to make the relationship.
reg.students[0].Idea = reg.idea;
Right now my POST actions for Create and Edit have rather long function definitions because there are a lot of variables and my bind attribute contains all of them.
public ActionResult Create([Bind(Include = "ProjectName,ProjectDescription,DateReceived,EffectiveDate,ExpirationDate,GeneralContractor,ProjectTerm,ProjectType,SubmissionNumber,PolicyNumber,Status,Underwriter,Division,BrokerCity,TAName,Branch,FirstNamedInsuredAddress,FirstNamedInsured,ProjectAddress")] Project project) {
and
public ActionResult Edit([Bind(Include = "ProjectID,ProjectName,ProjectDescription,DateReceived,EffectiveDate,ExpirationDate,GeneralContractor,ProjectTerm,ProjectType,SubmissionNumber,PolicyNumber,Status,Underwriter,Division,BrokerCity,TAName,Branch,FirstNamedInsuredAddress,FirstNamedInsured,ProjectAddress")] Project project) {
Is there an alternative to this that would make the definitions shorter?
Here is my model:
public class Project
{
public Project()
{
FirstNamedInsuredAddress = new Address();
ProjectAddress = new Address();
}
[Key]
public int ProjectID { get; set; }
[Required]
[StringLength(150)]
[Display(Name = "Project Name")]
public string ProjectName { get; set; }
[StringLength(1000)]
[Display(Name = "Project Description")]
public string ProjectDescription { get; set; }
[Display(Name = "Date Received")]
public string DateReceived { get; set; }
[Display(Name = "Effective Date")]
public string EffectiveDate { get; set; }
[Display(Name = "Expiration Date")]
public string ExpirationDate { get; set; }
[StringLength(150)]
[Display(Name = "General Contractor")]
public string GeneralContractor { get; set; }
[StringLength(25)]
[Display(Name = "Project Term")]
public string ProjectTerm { get; set; }
[Display(Name = "Project Type")]
public string ProjectType { get; set; }
[Required]
[Display(Name = "Submission Number")]
public long SubmissionNumber { get; set; }
[StringLength(20)]
[Display(Name = "Policy Number")]
public string PolicyNumber { get; set; }
public string Status { get; set; }
[StringLength(100)]
public string Underwriter { get; set; }
public string Division { get; set; }
[StringLength(50)]
[Display(Name = "Broker/City")]
public string BrokerCity { get; set; }
[StringLength(100)]
[Display(Name="TA Name")]
public string TAName { get; set; }
public string Branch { get; set; }
[Display(Name="First Named Insured Address")]
public Address FirstNamedInsuredAddress { get; set; }
[StringLength(150)]
[Display(Name="First Named Insured")]
public string FirstNamedInsured { get; set; }
[Display(Name="Project Address")]
public Address ProjectAddress { get; set; }
public class Address
{
[StringLength(150)]
[Display(Name="Line 1")]
public string Line1 { get; set; }
[StringLength(150)]
[Display(Name="Line 2")]
public string Line2 { get; set; }
[StringLength(100)]
public string City { get; set; }
public string State { get; set; }
[Display(Name="Zip Code")]
public int? ZipCode { get; set; }
[StringLength(100)]
public string County { get; set; }
}
}
As an alternative to the Include , you can use the Exclude. It will only exclude the properties that you do not want post. Probably, it will lesser in most of the cases or if you want, you can remove both include and exclude , and all the data will be posted .
Ex:
[HttpPost]
[ActionName("Edit")]
public ActionResult Edit([Bind(Exclude = "GeneralContractor")] Project project)
{
}
More/Useful Information:http://csharp-video-tutorials.blogspot.in/2013/05/part-21-including-and-excluding.html
I am trying to implement Asp.net Identity 2.0 with DB first.
I have imported my model.edmx into the project. It contains all the tables I need with the correct information and structure.
In the database there is a table called 'FSKUsers' I have edited this to contain the needed fields of the AspNetUsers which is the default table for Identity 2.0
So in my Identity DB Context I have mapped my FskUser class (which is a high level user for Identity sake)
public class IdentityDbContext : IdentityDbContext<FskUser, FskRole, int, FskUserLogin, FskUserRole, FskUserClaim>
{
public IdentityDbContext()
: base("FSK_FskNetworksEntities")
{
}
protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
var userEntity = modelBuilder.Entity<FskUser>();
userEntity.ToTable("FSKUsers", "dbo");
userEntity.Property(p => p.Id).HasColumnName("FSKUserId");
userEntity.Property(p => p.PasswordHash).HasColumnName("Password");
}
public static IdentityDbContext Create()
{
return new IdentityDbContext();
}
}
So basically I want to map the class FskUser to the Data Base table called FSKUser which is also contained in my .edmx model.
When I run the website I get the following error.
The entity type FskUser is not part of the model for the current context
My two POCO classes:
The one from my edmx model:
public partial class FSKUser
{
public FSKUser()
{
this.AspNetUserClaims = new HashSet<AspNetUserClaim>();
this.AspNetUserLogins = new HashSet<AspNetUserLogin>();
this.FSKDevices = new HashSet<FSKDevice>();
this.FSKEventLogs = new HashSet<FSKEventLog>();
this.FSKReports = new HashSet<FSKReport>();
this.FSKTransactions = new HashSet<FSKTransaction>();
this.FSKTriggers = new HashSet<FSKTrigger>();
this.UdlDownloads = new HashSet<UdlDownload>();
this.AspNetRoles = new HashSet<AspNetRole>();
this.FSKCompanies = new HashSet<FSKCompany>();
}
public int FSKUserId { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
public bool EmailConfirmed { get; set; }
public string PhoneNumber { get; set; }
public bool PhoneNumberConfirmed { get; set; }
public string Password { get; set; }
public string SecurityStamp { get; set; }
public bool TwoFactorEnabled { get; set; }
public Nullable<System.DateTime> LockoutEndDateUtc { get; set; }
public bool LockoutEnabled { get; set; }
public int AccessFailedCount { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public byte FSKAccessLevelId { get; set; }
public string AddressStreet1 { get; set; }
public string AddressStreet2 { get; set; }
public string AddressStreet3 { get; set; }
public string AddressPostCode { get; set; }
public Nullable<int> CreatorId { get; set; }
public Nullable<System.DateTime> CreateDate { get; set; }
public string ConfirmationToken { get; set; }
public Nullable<bool> IsConfirmed { get; set; }
public Nullable<System.DateTime> LastPasswordFailureDate { get; set; }
public Nullable<int> PasswordFailuresSinceLastSuccess { get; set; }
public Nullable<System.DateTime> PasswordChangedDate { get; set; }
public string PasswordVerificationToken { get; set; }
public string PasswordVerificationTokenExpirationDate { get; set; }
public bool IsDeleted { get; set; }
public Nullable<int> CostCentreId { get; set; }
public Nullable<int> AdminPasswordResetUserId { get; set; }
public Nullable<System.DateTime> PreviousLogInDate { get; set; }
public System.Guid msrepl_tran_version { get; set; }
public virtual ICollection<AspNetUserClaim> AspNetUserClaims { get; set; }
public virtual ICollection<AspNetUserLogin> AspNetUserLogins { get; set; }
public virtual ICollection<FSKDevice> FSKDevices { get; set; }
public virtual ICollection<FSKEventLog> FSKEventLogs { get; set; }
public virtual ICollection<FSKReport> FSKReports { get; set; }
public virtual ICollection<FSKTransaction> FSKTransactions { get; set; }
public virtual ICollection<FSKTrigger> FSKTriggers { get; set; }
public virtual ICollection<UdlDownload> UdlDownloads { get; set; }
public virtual ICollection<AspNetRole> AspNetRoles { get; set; }
public virtual ICollection<FSKCompany> FSKCompanies { get; set; }
}
The one I use in my Identity Config
public class FskUser : IdentityUser<int, FskUserLogin, FskUserRole, FskUserClaim>
{
[Display(Name = "First Name")]
[Required(ErrorMessage = "First Name is Required.")]
public string FirstName { get; set; }
[Display(Name = "Last Name")]
[Required(ErrorMessage = "Last Name is Required.")]
public string LastName { get; set; }
[MaxLength(20)]
[Display(Name = "Cell Number")]
[RegularExpression(#"^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$", ErrorMessage = "Entered phone format is not valid.")]
[StringLength(10, ErrorMessage = "The {0} must be 10 numbers long.", MinimumLength = 10)]
public override string PhoneNumber { get; set; }
[Display(Name = "Access Level")]
public byte? FSKAccessLevelId { get; set; }
[Display(Name = "Street Address 1")]
public string AddressStreet1 { get; set; }
[Display(Name = "Street Address 2")]
public string AddressStreet2 { get; set; }
[Display(Name = "Street Address 3")]
public string AddressStreet3 { get; set; }
[Display(Name = "Postal Code")]
public string AddressPostCode { get; set; }
[Display(Name = "Previous Login")]
public Nullable<DateTime> PreviousLogInDate { get; set; }
[Display(Name = "Account Confirmed")]
public Nullable<bool> IsConfirmed { get; set; }
[Display(Name = "Last Password Failier")]
public Nullable<DateTime> LastPasswordFailureDate { get; set; }
[Display(Name = "Password Last Changed")]
public Nullable<DateTime> PasswordChangedDate { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<FskUser, int> manager)
{
//TODO: add option for web and api (to create different auth types
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
When you use Database first approach with edmx file OnModelCreating method is never called. You may check that with debugger.