简体   繁体   中英

Entity Framework Code First Lazy Loading without Include(“A”) method

I have a class:

class Client
{
  public string Name {get;set;}

  public virtual A{get;set;}

  public virtual B{get;set;}
}

I'm filling A and B properties like that:

public Client GetById(Guid id)
{
    using (DataContext context = new DataContext())
    {
        context.Configuration.LazyLoadingEnabled = true;
        var query = context.Clients.Include("A");
        query = query.Include("B");
        return query.FirstOrDefault(r => r.Id == id);
    }
}

Context inherited from System.Data.Entity.DbContext

If I'll rename A or B I'll have to change this Include("A") manually. No good...

Please let me know if there is another convenient way how to fill this properties?

Thanks in advance.

context.Clients.Include(x => x.A).Include(x => x.B)

至少,智能感知将以这种方式重命名。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM