I’m creating a database in EF4.1 Code First. I’ve got a one-to-many relationship of health forms with health dependents. A health form has 0-5 dependents. When I create the healthform, the dependents table is created for me by using
modelBuilder.Entity<BenefitsForm>().HasMany(t => t.Dependents).WithOptional().WillCascadeOnDelete();
However, when I use the retrieve method:
return context.BenefitsForm;
it does not display the Dependents table join, only the BenefitsForms. How can I get it to show the BenefitsForm table linked with Dependents table?
One way is to use the
Include()method – http://msdn.microsoft.com/en-us/library/bb738708.aspxAnother way is to enable LazyLoading on your context – http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontextoptions.lazyloadingenabled.aspx