c# - Entity Framework 1:1 Relationship Identity Colums -


i cannot life of me 2 separate tables save relationship , 2 identity columns. keep getting errors dependent property in referentialconstraint mapped store-generated column. column: 'olsterminalid'. can't imagine setup abnormal.

[datacontract]     public class olsdata {         private static readonly datetime theunixepoch = new datetime(1970, 1, 1, 0, 0, 0, 0, datetimekind.utc);      [databasegenerated(databasegeneratedoption.identity)]     public int olsdataid { get; set; }      [datamember(name = "id")]     public int id { get; set; }      public datetime timestamp { get; set; }      [datamember(name = "created")]     [notmapped]     public double created {         { return (timestamp - theunixepoch).totalmilliseconds; }         set { timestamp = theunixepoch.addmilliseconds(value); }     }      [inverseproperty("olsdata")]     [datamember(name = "terminal")]     public virtual olsterminal olsterminal { get; set; } }  [datacontract] public class olsterminal {     [databasegenerated(databasegeneratedoption.identity)]     public int olsterminalid { get; set; }      public int olsdataid { get; set; }      [datamember(name = "account")]     [notmapped]     public virtual olsaccount olsaccount { get; set; }      [datamember(name = "terminalid")]     public string terminalid { get; set; }      [datamember(name = "merchantid")]     public string merchantid { get; set; }      public virtual olsdata olsdata { get; set; } }   public class olsdatacontext : dbcontext {         protected override void onmodelcreating(dbmodelbuilder amodelbuilder) {             amodelbuilder.conventions.remove<pluralizingtablenameconvention>();         }          public olsdatacontext(string aconnectionstring) : base(aconnectionstring) {}         public dbset<olsdata> olsdata { get; set; }         public dbset<olsterminal> olsterminal { get; set; }         public dbset<olsaccount> olsaccount { get; set; }      } 

it because 1:1 relationship in ef build on primary keys. fk in olsterminal table must olsterminalid , fk cannot autogenerated - must value of pk olsdata.

the reason why must done way requirement uniqueness of fk value in dependent entity build real 1:1 instead of 1:n. ef doesn't support unique constraints / candidate keys yet way how enforce uniqueness use place fk on pk of dependent entity.


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -