c# - The foreign key component 'X' is not a declared property on type 'Y'. Verify that it has not been explicitly excluded -


it seems pretty common issue, i've tried , can't see issues.

it seems if issue started today. full error message:

"the foreign key component 'allocationid' not declared property on type 'portfoliosection'. verify has not been explicitly excluded model , valid primitive property."

model:

public class portfoliosection  {     .... stuff      public int allocationid { set; get; }      [foreignkey("allocationid")]     public virtual allocation allocation { get; set; }      .... more stuff  } public class allocation  {      ... stuff        [foreignkey("portfoliosections")]     public int allocationid { set; get; }       public string name { set; get;}       public string color { set; get; }       public int sortorder { set; get; }         public virtual list<portfoliosection> portfoliosections { get; set; }   } 

i'm not doing weird w/ configuration can see cause issue. key allocation allocationid , not id?

so far i've tried: 1. removing navigation property porfoliosection allocation. 2. putting foriegnkey attribute on allocationid (foreignkey("allocation")) instead of navigation property.

you have few attributes misplaced. if change:

[foreignkey("portfoliosections")] public int allocationid { set; get; } 

to:

[key] public int allocationid { set; get; } 

then should work fine. issue declared key (allocationid primary key assuming) foreignkey portfoliosections table.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -