asp.net mvc 3 - EF 5.0 Code First navigation property null for only one property -
i seem having problem following model using ef 5.0 codefirst:
when try , listing salesplanactivity unable activity name navigational property
i.e. if model salesplanactivity, model.activity <--- null, yet model.company , model.salesplan fine.
the idea company has library of activities, each company has number of salesplans, each salesplans has number of activities (which come activity library)
am mapping incorrectly?
should mapping between salesplanactivity , activity 1:1?
i've added following relationships
// relationships modelbuilder.entity<salesplanactivity>().hasrequired(t => t.activity) .withmany(t => t.salesplanactivities) .hasforeignkey(d => new { d.companyid, d.activityid }); modelbuilder.entity<salesplanactivity>().hasrequired(t => t.salesplan) .withmany(t => t.salesplanactivities) .hasforeignkey(d => new { d.salesplanid, d.companyid }); public class activity : iauditable { [key, column(order = 0), databasegenerated(databasegeneratedoption.identity)] public int activityid { get; set; } [key, column(order = 1)] public int companyid { get; set; } public virtual company company { get; set; } [display(name = "activity name"), required, stringlength(256)] public string name { get; set; } public virtual icollection<salesplanactivity> salesplanactivities { get; set; } [datatype(datatype.datetime)] public datetime createdon { get; set; } public guid createdby { get; set; } [datatype(datatype.datetime)] public datetime modifiedon { get; set; } public guid modifiedby { get; set; } } public class company : iauditable { [key, databasegenerated(databasegeneratedoption.identity)] public int companyid { get; set; } [display(name = "company name"), required, stringlength(256)] public string name { get; set; } public virtual icollection<activity> activities { get; set; } public virtual icollection<salesplan> salesplans { get; set; } [datatype(datatype.datetime)] public datetime createdon { get; set; } public guid createdby { get; set; } [datatype(datatype.datetime)] public datetime modifiedon { get; set; } public guid modifiedby { get; set; } } public class salesplan : iauditable { [key, column(order = 0), databasegenerated(databasegeneratedoption.identity)] public int salesplanid { get; set; } [key, column(order = 1)] public int companyid { get; set; } public virtual company company { get; set; } [display(name = "sales plan name"), required, stringlength(256)] public string name { get; set; } [display(name = "total points"), required] public decimal totalpoints { get; set; } public virtual icollection<salesplanactivity> salesplanactivities { get; set; } [datatype(datatype.datetime)] public datetime createdon { get; set; } public guid createdby { get; set; } [datatype(datatype.datetime)] public datetime modifiedon { get; set; } public guid modifiedby { get; set; } } public class salesplanactivity : iauditable { [key, column(order = 0)] public int salesplanid { get; set; } public virtual salesplan salesplan { get; set; } [key, column(order = 1)] public int companyid { get; set; } public virtual company company { get; set; } [key, column(order = 2)] public int activityid { get; set; } public virtual activity activity { get; set; } public decimal points { get; set; } public int sortorder { get; set; } [datatype(datatype.datetime)] public datetime createdon { get; set; } public guid createdby { get; set; } [datatype(datatype.datetime)] public datetime modifiedon { get; set; } public guid modifiedby { get; set; } }
Comments
Post a Comment