1
我有以下DTO:填寫DTO模式與實體值
public class EbookDTO {
public Int32 EbookId { get; set; }
public Int32 CoverId { get; set; }
public Int32 DocumentId { get; set; }
}
而且我有以下實體框架的實體:
public class EbookFile {
public Int32 EbookId { get; set; }
public Int32 FileId { get; set; }
public virtual Ebook Ebook { get; set; }
public virtual File File { get; set; }
}
public class File {
public Int32 Id { get; set; }
public Int32 EbookFileId { get; set; }
public String Name { get; set; }
public virtual EbookFile EbookFile { get; set; }
}
我有以下EbookDTO
列表:
List<EbookDTO> ebooks = new List<EbookDTO>() {
new EbookDTO { Id = 1 },
new EbookDTO { Id = 2 }
}
我需要爲這些電子書中的每一本電子書獲取他們的DocumentId和CoverId:
- 在contexts.EbooksFiles得到具有
Ebook.Id
=DTO.EbookId;
- 從(1)取各
EbookFile
的文件ID的那些; - 在
context.Files
中查找帶有(2)中所帶參數的那些; - 每個
EbookDTO
DocumentId
將是名爲「文檔」的文件,並且EbookDTO
CoverId
將是名稱爲Cover的文件。
我嘗試了一些疑問,例如:
context
.EbooksFiles
.Where(x => ebooks.Select(y => y.Id).Contains(x.EbookId))
但我不知道如何測試的文件名,獲得其ID,並添加定義DocumentId
每個EbookDTO
的CoverId
。