I have a problem with EF7 in a web application with which I could use some help. I am currently using EF7 RC1.
Here are some models that illustrate my problem.
Contact
public class Contact
{
public Guid Id { get; set; }
public string Desc { get; set; }
public ContactType ContactType { get; set; }
}
ContactType
public class ContactType
{
public Guid Id { get; set; }
public string Desc { get; set; }
public ICollection<Contact> Contacts { get; set; }
}
These models are linked through the Fluent API as follows:
modelBuilder.Entity<Contact>(entity => {
entity
.HasOne(c => c.ContactType)
.WithMany(ct => ct.Contacts)
.IsRequired();
});
My need is to be able to retrieve a collection of Contact objects from a database with the ContactType property loaded. EF makes this pretty simple:
using(var context = new MyDbContext()) {
var contacts = await context
.Contacts
.Include(c => c.ContactTypes)
.Where()
.ToListAsync();
}
, ContactType Contact ( - .Include() ) EF Contacts ContactType, , ContactTypes ContactTypes, . , , - JSON - .
, EF ( ) ContactType, "" . - EF? ? , , ?
, :
- .AsNoTracking() EF (, ,
ContactType )
- Json.NET (
,
, ).