c# - Entity Framework mapping error -
i have following entities defined as:
public partial class user { public user() { this.userclaims = new list<userclaim>(); this.userroles = new list<userrole>(); this.userlogins = new list<userlogin>(); } public long id { get; set; } public string username { get; set; } public string firstname { get; set; } public string lastname { get; set; } public string middlename { get; set; } public nullable<byte> gender { get; set; } public long addressid { get; set; } public string email { get; set; } public bool emailconfirmed { get; set; } public string passwordhash { get; set; } public string securitystamp { get; set; } public string phonenumber { get; set; } public bool phonenumberconfirmed { get; set; } public bool twofactorenabled { get; set; } public nullable<datetime> lockoutenddateutc { get; set; } public bool lockoutenabled { get; set; } public int accessfailedcount { get; set; } public virtual address address { get; set; } public virtual icollection<userclaim> userclaims { get; set; } public virtual icollection<userrole> userroles { get; set; } public virtual icollection<userlogin> userlogins { get; set; } } and
public partial class userclaim { public int id { get; set; } public string claimtype { get; set; } public string claimvalue { get; set; } public long userid { get; set; } public virtual user user { get; set; } } and mappings follows:
public class usermap : entitytypeconfiguration<user> { public usermap() { // primary key this.haskey(t => t.id); // properties this.property(t => t.username) .isrequired() .hasmaxlength(50); this.property(t => t.firstname) .hasmaxlength(50); this.property(t => t.lastname) .hasmaxlength(50); this.property(t => t.middlename) .hasmaxlength(50); this.property(t => t.email) .hasmaxlength(100); this.property(t => t.passwordhash) .hasmaxlength(100); this.property(t => t.securitystamp) .hasmaxlength(100); this.property(t => t.phonenumber) .hasmaxlength(25); // table & column mappings this.totable("users"); this.property(t => t.id).hascolumnname("id"); this.property(t => t.username).hascolumnname("username"); this.property(t => t.firstname).hascolumnname("firstname"); this.property(t => t.lastname).hascolumnname("lastname"); this.property(t => t.middlename).hascolumnname("middlename"); this.property(t => t.gender).hascolumnname("gender"); this.property(t => t.addressid).hascolumnname("addressid"); this.property(t => t.email).hascolumnname("email"); this.property(t => t.emailconfirmed).hascolumnname("emailconfirmed"); this.property(t => t.passwordhash).hascolumnname("passwordhash"); this.property(t => t.securitystamp).hascolumnname("securitystamp"); this.property(t => t.phonenumber).hascolumnname("phonenumber"); this.property(t => t.phonenumberconfirmed).hascolumnname("phonenumberconfirmed"); this.property(t => t.twofactorenabled).hascolumnname("twofactorenabled"); this.property(t => t.lockoutenddateutc).hascolumnname("lockoutenddateutc"); this.property(t => t.lockoutenabled).hascolumnname("lockoutenabled"); this.property(t => t.accessfailedcount).hascolumnname("accessfailedcount"); // relationships this.hasmany(t => t.userroles) .withmany(t => t.users) .map(m => { m.totable("useruserroles"); m.mapleftkey("userid"); m.maprightkey("roleid"); }); this.hasrequired(t => t.address) .withmany(t => t.users) .hasforeignkey(d => d.addressid); this.hasmany(t => t.userclaims) .withoptional(t => t.user) .hasforeignkey(d => d.userid); } } and
public class userclaimmap : entitytypeconfiguration<userclaim> { public userclaimmap() { // primary key this.haskey(t => t.id); // properties // table & column mappings this.totable("userclaims"); this.property(t => t.id).hascolumnname("id"); this.property(t => t.claimtype).hascolumnname("claimtype"); this.property(t => t.claimvalue).hascolumnname("claimvalue"); this.property(t => t.userid).hascolumnname("userid"); // relationships this.hasrequired(t => t.user) .withmany(t => t.userclaims) .hasforeignkey(d => d.userid); } } userclaim table has foreign key on column "userid". database tables looks follows.
while running application receive following error. 1 or more validation errors detected during model generation:
userclaim_user_source: : multiplicity not valid in role 'userclaim_user_source' in relationship 'userclaim_user'. because dependent role refers key properties, upper bound of multiplicity of dependent role must '1'. userclaim_user_target_userclaim_user_source: : types of properties in dependent role of referential constraint must same corresponding property types in principal role. type of property 'id' on entity 'userclaim' not match type of property 'id' on entity 'user' in referential constraint 'userclaim_user'.
i tried changing mappings couldn't resolve error. can please me resolve error?
Comments
Post a Comment