c# - Code first Model foreign key property SocialDetails is null even when the ID's match in the DB -



c# - Code first Model foreign key property SocialDetails is null even when the ID's match in the DB -

i'm trying debug dbcontext query , generated sql looks this

select [extent1].[id] [id], [extent1].[name] [name], [extent1].[socialdetails_id] [socialdetails_id] [dbo].[items] [extent1] [extent1].[id] = @p__linq__0

however foreign key property socialdetails null when i've checked id's in teh db

public class item { public int id { get; set; } public string name { get; set; } [required] public user user { get; set; } [required] public socialdetails socialdetails { get; set; } etc

what best way find out why socialdetails null?

you have lazy loading disabled.

as suggested matt whetton, seek this:

var items = x in dbcontext.items.include("socialdetails") x.id = id select x;

where dbcontext context, , have dbset named items

see link (msdn):

loading related objects

c# entity-framework orm visual-studio-2012 dbcontext

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -