请考虑下表。
表:文档
docID, docNr, docScanTime
10, 99, 2012-08-02
11, 98, 2012-08-02
12, 97, 2012-08-02
13, 96, 2012-08-02
14, 95, 2012-08-02
表:DocumentFlag
用户 ID、文档 ID、isDelete、isArchive 41、10、1
、NULL 42、11
、NULL、1
Document 表中有 5 行,DocumentFlag 表中有 2 行。我正在使用以下 Linq 语句来获取文档列表。
List<Document> docList = new List<Document>();
using (AppDataContext context = data.GetDataContext())
{
docList = (from d in context.Documents
join f in context.DocumentFlags on d.docID equals f.docID
where f.usrID == userID
select new Document
{
DocID = d.docID,
DocNr = d.docNr,
ScanTime = d.docScanTime.Value,
UserID = f.userID,
IsDelete = f.isDelete.Value,
IsArchive = f.isArchive.Value,
}).ToList<Document>();
}
public class Document
{
public int DocID {get; set;}
public int DocNr {get; set;}
public DateTime DocScanTime {get; set;}
public int UserID {get; set;}
public byte IsDelete {get; set;}
public byte IsArchive {get; set;}
}
但问题是我只得到了 DocumentFlag 中的两行。我想获取 Document 中的所有行以及列表中 DocumentFlag 中的信息。如果 DocumentFlag 不包含有关文档的信息,则它可以将 null 存储在 isDelete 或 isArchive 中。
有任何想法吗?