entity framework - Why am I getting Invalid column name on field names that don't exist in my model? -


i querying entity ef 5.0 code first / dbcontext. getting following errors:

invalid column name 'retainedearningsaccount_key'. invalid column name 'plsummaryaccount_key'.

however, neither of these fields exist in model. assume default configuration/mapping happening here, don't know is. here model class in question:

public glentity()     {         this.accessentities = new hashset<accessentity>();         this.bankaccountglaccounts = new hashset<bankaccountglaccount>();         this.batchrestrictionentities = new hashset<batchrestrictionentity>();         this.budgetversions = new hashset<budgetversion>();         this.calendarcrossrefs = new hashset<calendarcrossref>();         this.consoldetails = new hashset<consoldetail>();         this.consolheaders = new hashset<consolheader>();         this.defaultbudgetversions = new hashset<defaultbudgetversion>();         this.departments = new hashset<department>();         this.expensecodedetails = new hashset<expensecodedetail>();         this.glaccounts = new hashset<glaccount>();         this.journals = new hashset<journal>();         this.postingrules = new hashset<postingrule>();         this.processes = new hashset<process>();         this.properties = new hashset<property>();         this.recurringjournals = new hashset<recurringjournal>();         this.recurringtransactiongls = new hashset<recurringtransactiongl>();         this.entitiesalternate = new hashset<glentity>();         this.glintercompaniesdestinationentities = new hashset<glintercompany>();         this.glintercompaniessourceentities = new hashset<glintercompany>();         this.transgls = new hashset<transgl>();     }      public system.guid key { get; set; }     public string entityid { get; set; }     public string description { get; set; }     public nullable<short> currentfiscalyear { get; set; }     public nullable<short> currentprd { get; set; }     public string entitytype { get; set; }     public string allowpostingyn { get; set; }     public string nextjournal { get; set; }     public nullable<system.guid> companykey { get; set; }     public nullable<system.guid> retainedearningsacctkey { get; set; }     public nullable<system.guid> plsummaryacctkey { get; set; }     public string accountingtype { get; set; }     public string usercreated { get; set; }     public system.datetime created { get; set; }     public string useredited { get; set; }     public nullable<system.datetime> edited { get; set; }     public nullable<system.guid> alternateentitykey { get; set; }     public string trackjobs { get; set; }     public string trackunits { get; set; }      public virtual icollection<accessentity> accessentities { get; set; }     public virtual icollection<bankaccountglaccount> bankaccountglaccounts { get; set; }     public virtual icollection<batchrestrictionentity> batchrestrictionentities { get; set; }     public virtual icollection<budgetversion> budgetversions { get; set; }     public virtual icollection<calendarcrossref> calendarcrossrefs { get; set; }     public virtual company company { get; set; }     public virtual icollection<consoldetail> consoldetails { get; set; }     public virtual icollection<consolheader> consolheaders { get; set; }     public virtual icollection<defaultbudgetversion> defaultbudgetversions { get; set; }     public virtual icollection<department> departments { get; set; }     public virtual icollection<expensecodedetail> expensecodedetails { get; set; }     public virtual icollection<glaccount> glaccounts { get; set; }     public virtual icollection<journal> journals { get; set; }     public virtual icollection<postingrule> postingrules { get; set; }     public virtual icollection<process> processes { get; set; }     public virtual icollection<property> properties { get; set; }     public virtual icollection<recurringjournal> recurringjournals { get; set; }     public virtual icollection<recurringtransactiongl> recurringtransactiongls { get; set; }     public virtual icollection<glentity> entitiesalternate { get; set; }     public virtual glentity entityalternate { get; set; }     public virtual icollection<glintercompany> glintercompaniesdestinationentities { get; set; }     public virtual icollection<glintercompany> glintercompaniessourceentities { get; set; }     public virtual icollection<transgl> transgls { get; set; }     public virtual glaccount retainedearningsaccount { get; set; }     public virtual glaccount plsummaryaccount { get; set; }  } 

and here mapping:

public glentity_mapping()     {                                   this.haskey(t => t.key);                   this.totable("tblentity");           this.property(t => t.key).hascolumnname("keyguid");           this.property(t => t.entityid).hascolumnname("entityid").isunicode(false).hasmaxlength(10);           this.property(t => t.description).hascolumnname("description").isunicode(false).hasmaxlength(50);           this.property(t => t.currentfiscalyear).hascolumnname("currentfiscalyear");           this.property(t => t.currentprd).hascolumnname("currentprd");           this.property(t => t.entitytype).hascolumnname("entitytype").isunicode(false).isfixedlength().hasmaxlength(1);           this.property(t => t.allowpostingyn).hascolumnname("allowpostingyn").isunicode(false).isfixedlength().hasmaxlength(1);           this.property(t => t.nextjournal).hascolumnname("nextjournal").isunicode(false).hasmaxlength(20);           this.property(t => t.companykey).hascolumnname("company");           this.property(t => t.retainedearningsacctkey).hascolumnname("retainedearningsacct");           this.property(t => t.plsummaryacctkey).hascolumnname("plsummaryacct");           this.property(t => t.accountingtype).hascolumnname("accountingtype").isunicode(false).isfixedlength().hasmaxlength(1);           this.property(t => t.usercreated).hascolumnname("usercreated").isrequired().isunicode(false).hasmaxlength(50);           this.property(t => t.created).hascolumnname("created");           this.property(t => t.useredited).hascolumnname("useredited").isunicode(false).hasmaxlength(50);           this.property(t => t.edited).hascolumnname("edited");           this.property(t => t.alternateentitykey).hascolumnname("alternateentity");           this.property(t => t.trackjobs).hascolumnname("trackjobs").isunicode(false).isfixedlength().hasmaxlength(1);           this.property(t => t.trackunits).hascolumnname("trackunits").isunicode(false).isfixedlength().hasmaxlength(1);           this.hasoptional(t => t.company).withmany(t => t.entities).hasforeignkey(d => d.companykey);           this.hasoptional(t => t.entityalternate).withmany(t => t.entitiesalternate).hasforeignkey(d => d.alternateentitykey);      } 

why getting error on non-existent properties?

because of abbreviation acct instead of account in these properties...

public nullable<system.guid> retainedearningsacctkey { get; set; } public nullable<system.guid> plsummaryacctkey { get; set; } 

...ef conventions not recognize properties foreign keys for

public virtual glaccount retainedearningsaccount { get; set; } public virtual glaccount plsummaryaccount { get; set; } 

you can either rename fk properties retainedearningsaccountkey , plsummaryaccountkey. ef should recognize them correctly according rule "fk property name = navigation property name + primary key name of target entity".

or define properties fks fluent api in glentity_mapping:

this.hasoptional(t => t.retainedearningsaccount)     .withmany(a => a.someinversecollection1)     .hasforeignkey(t => t.retainedearningsacctkey);  this.hasoptional(t => t.plsummaryaccount)     .withmany(a => a.someinversecollection2)     .hasforeignkey(t => t.plsummaryacctkey); 

someinversecollection1/2 related collections in glaccount or use withmany() without lambda parameter if there no inverse collections in class.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

mysql - Pass value between different pages (form) with PHP -