0

If I have the following objects:

public class Application 
{
    public int ApplicationId { get; set; }
    public string Name { get; set; }
    public virtual ICollection<TestAccount> TestAccounts { get; set; }
}

public class TestAccount
{
    public int TestAccountId { get; set; }
    public int ApplicationId { get; set; }
    public string Name { get; set; }
    public virtual Application Application { get; set; }
}

EF Mapping looks like this:

modelBuilder.Entity<Application>()
    .HasMany(a => a.TestAccounts)
    .WithRequired(t => t.Application)
    .WillCascadeOnDelete(false);

In one part of my code I want to retrieve data for Application and have it return TestAccount data.

In another part of my code I want to retrieve data for Application and have it NOT return TestAccount data.

Is there a way I can make this happen with LINQ or some other way?

1 Answers1

0

This question has already been answered here: Disable lazy loading by default in Entity Framework 4.

Basically, in the constructor of your DbContext, just add this:

this.Configuration.LazyLoadingEnabled = false;

I hope this helps.

EDIT

Also, if you want to know how to load it manually later, it should be a simple matter of using Include() like this:

var query = context.Application.Include(x => x.TestAccounts).ToList()

Community
  • 1
  • 1
Matt
  • 6,787
  • 11
  • 65
  • 112
  • Thanks a lot. I have another problem now. Will post and hope someone can help. –  Mar 06 '13 at 04:53