繁体   English   中英

从SQL Server数据库中选择linq两个对象

[英]Select with linq two object from SQL Server database

我有以下Log

int LogID
text Name
datetime CreationTime
text Content
int CreatorID

我尝试获取由具体Creator创建的所有日志

Creator creator = myDataContext.Creator.Single<Creator>(cr => cr.Name == name);
var query = (from l in myDataContext.Log
            where l.CreatorID == creator.CreatorID
            select l).ToList<Log>();

但在返回的列表中, Creator为空。

如何获得给定Creator的日志列表?

您需要设置LoadOptions:

DataLoadOptions dataLoadOptions = new DataLoadOptions();
dataLoadOptions.LoadWith<Log>(l => l.Creator);
myDataContext.LoadOptions = dataLoadOptions;
var logs = myDataContext.Logs.Include("Creator").Where(c => c.Creator.Name == name).ToList();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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