c# - ASP.NET MVC EF Unable to determine the principal end of association -


i've encountered problems associations while using entity framework. althought there other posts couldn't make working.

public class basejoboffer : ientity {     [key, foreignkey("file")]     public int id { get; set; }     public string name { get; set; }     public int fileid { get; set; }     public file file { get; set; } } public class file {     public int id { get; set; }     public string filename { get; set; }     public string contenttype { get; set; }     public byte[] content { get; set; }     public enums.filetype filetype { get; set; }     public int jobofferid { get; set; }     public virtual basejoboffer joboffer { get; set; } } 

and error says: there error running selected code generator:

'unable retrieve metadata model.joboffer'. unable determine principal end of association between types 'model.basejoboffer' , 'model.file'. principal end of association must explicitly configured using either relationship fluent api or data annotations.'

see article foreignkey attribute usage http://www.entityframeworktutorial.net/code-first/foreignkey-dataannotations-attribute-in-code-first.aspx

the foreignkey attribute should on either foreignkey property or foreignkeyid property

public class basejoboffer : ientity {     [key]     public int id { get; set; }     public string name { get; set; }      [foreignkey("file")     public int fileid { get; set; }      //or      [foreignkey("fileid")     public file file { get; set; } } 

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -