簡體   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