asp.net mvc - Error with one-to-many relationship in MVC Entity Framework 4 -
i following error when run code-first mvc app , try , visit either developeraccountmodel details page or view loads parent object , collection of developeraccountmodel: the navigation property 'redirects' not declared property on type 'developeraccountmodel'. @ point, not accessing property (which exist!) attempting load developeraccountmodel.
[table("sitedata")] public class developeraccountmodel { [required] [regularexpression("^[0-9]*$")] [display(name = "user id")] [key] [column("_rowid")] public long rowid { get; internal set; } // other properties removed [display(name = "redirects")] [notmapped] [inverseproperty("developeraccount")] public list<siteredirectmodel> redirects { get; internal set; } }
and dependent model
[table("siteredirects")] public partial class siteredirectmodel { [key] [column("_rowid")] [display(name = "rowid")] public int rowid { get; internal set; } [column("_siteid")] [display(name = "developer account id")] public long developeraccountmodelid { get; internal set; } [notmapped] [foreignkey("developeraccountmodelid")] public virtual developeraccountmodel developeraccount { get; internal set; } }
i have tried many variations of various tutorials , samples including other times or similar error occurs not seeing simple. can please?
simply, remove [notmapped]
attribute both properties. properties definition should like:
// in siteredirectmodel [foreignkey("developeraccountmodelid")] public virtual developeraccountmodel developeraccount { get; internal set; } // in developeraccountmodel [display(name = "redirects")] [inverseproperty("developeraccount")] public list<siteredirectmodel> redirects { get; internal set; }