次の表を検討してください。
表: ドキュメント
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 にある 2 つの行しか得られないことです。リスト内の DocumentFlag の情報を含む Document のすべての行を取得したい。DocumentFlag にドキュメントに関する情報が含まれていない場合は、isDelete または isArchive に null を格納できます。
何か案は?