Cal*_*vin 8 entity-framework code-first ef-code-first
我正在使用EF 5和Code First.我有一个类,我想总是急于加载一些属性.我删除了虚拟关键字,但它并不急于加载:
public class Person
{
public ICollection<Email> Emails { get; set; }
public Profile Profile {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
所以通过关闭延迟加载,它不会自动加载正确的加载吗?如果是这样,如何在不使用Include()的情况下归档?
谢谢!
Pau*_*aul 18
不,通过删除virtual关键字来关闭延迟加载不会自动启用急切加载.你需要Include相关Entity或Collection类似的:
var personWithProfile = ctx.People.Include(x => x.Profile).First();
var personWithProfileAndEmails = ctx.People.
.Include(x => x.Profile)
.Include(x => x.Emails)
.First();
Run Code Online (Sandbox Code Playgroud)
这是来自ADO.NET团队博客的精彩内容:http://blogs.msdn.com/b/adonet/archive/2011/01/31/using-dbcontext-in-ef-feature-ctp5-part-6 -上下相关-entities.aspx
| 归档时间: |
|
| 查看次数: |
10971 次 |
| 最近记录: |