linq to sql会自动延迟加载关联实体吗?
我认为它会,但我找不到一篇文章陈述它.
这取决于你如何定义"懒惰负载".
如果你说
var person = (from p in db.People where p.PersonId = pid select p).First(); var spouse = person.Spouse; // based on the SpouseId FK // back into the People table.
然后,这将是"懒惰加载",因为第二个对象在被引用之前不会从数据库中拉出.但是,这将需要两个数据库查询.
但是,如果你要说,
var family = (from p in db.People where p.PersonId = pid select new { Name = p.Name, SpouseName = p.Spouse.Name }).First();
然后,Linq将自动执行连接并从单个数据库查询中的两个记录中加载信息.