c# - "EntityType has no key defined" exception although key is defined with HasKey -


using ef 5 (reverse engineered code first), model working fine until stopped.

\tsystem.data.entity.edm.edmentitytype: : entitytype 'projectsdate' has no key defined. define key entitytype.

\tsystem.data.entity.edm.edmentitytype: : entitytype 'projectsrisk' has no key defined. define key entitytype.

i define key using fluent api rather attributes, here projectsdates classes.

public partial class projectsdate {     public string osprojectcode { get; set; }     public nullable<system.datetime> targetstart { get; set; }     public nullable<system.datetime> enddateoriginal { get; set; }     public nullable<system.datetime> enddatechangecontrol { get; set; }     public nullable<system.datetime> enddateactual { get; set; }     public nullable<system.datetime> goliveagreed { get; set; }     public nullable<system.datetime> goliveactual { get; set; }     public virtual project project { get; set; } } 
public class projectsdatemap : entitytypeconfiguration<projectsdate> {     public projectsdatemap()     {         // primary key         this.haskey(t => t.osprojectcode);          // properties         this.property(t => t.osprojectcode)             .isrequired()             .hasmaxlength(10);          // table & column mappings         this.totable("projectsdates");         this.property(t => t.osprojectcode).hascolumnname("osprojectcode");         this.property(t => t.targetstart).hascolumnname("targetstart");         this.property(t => t.enddateoriginal).hascolumnname("enddateoriginal");         this.property(t => t.enddatechangecontrol).hascolumnname("enddatechangecontrol");         this.property(t => t.enddateactual).hascolumnname("enddateactual");         this.property(t => t.goliveagreed).hascolumnname("goliveagreed");         this.property(t => t.goliveactual).hascolumnname("goliveactual");          // relationships         this.hasrequired(t => t.project)             .withoptional(t => t.projectsdate);      } } 

why doesn't ef see fluent api mapping?

for reason (probably bug), fluentapi needs key defined in convention way - - classname + id, or in case:

projectsdateid 

this way metadata created ef can acknowledge fact related. annoying but...


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -