Hi!
I have the following code in Linq to Entity:
var policy= from pol in conn.Policy
where pol.Product.DESCRIPTION=="someProduct"
SELECT pol;
Then, the table Policy, has some dependencies for a table called Entity. If I do this:
foreach(Policy p in policy){
if(!p.Entity.IsLoaded) p.Entity.Load();
IEnumerable<Entity> entities= from ent in p.Entity
Where ent.EntityType.DESCRIPTION=="SomeEntityType"
select ent;
Console.Writeline(entities.ElementAt(0).NAME);
}
It says, "Object not set to an instance", but if I do:
foreach(Policy p in policy){
if(!p.Entity.IsLoaded) p.Entity.Load();
foreach(Entity et in p.Entity)Console.Write(et.NAME);
}
It works! Can anyone tell me why?
Thank you, Best regards.