1
public class JoinModel
{
public Book Book { get; set; }
public BookOrder BookOrder { get; set; }
}
public class Book
{
public int BookID { get; set; }
public string UniqueID{ get; set; }
public int Year { get; set; }
public int BookNumber { get; set; }
public int Value { get; set; }
}
public class BookOrder
{
public int BookOrderID { get; set; }
public string UniqueID{ get; set; }
public int Year { get; set; }
public int BookNumber { get; set; }
public DateTime OrderDate { get; set; }
}
試圖編寫將執行左連接並返回列表的lambda表達式。該列表應包含Books,但 BookOrder可以爲null。Linq左連接lambda表達式和結果到列表
我已經試過下面這將導致生成錯誤:
無法隱式轉換 「System.Collections.Generic.IEnumerable < ... BookOrder>到..BookOrder 的顯式轉換存在的類型(是你失蹤5號線一投?)(紅色 squigles上BKO)
我不能夠改變書或BookOrder類,因爲這是一個第三方,即我要參加下面列出的3個條件。
List<JoinModel> lstJoinModel = new List<JoinModel>();
Line 1 - lstJoinModel = Context.Books
Line 2 - .GroupJoin(Context.BookOrder,
Line 3 - bk => new { bk.UniqueID, bk.Year, bk.PostingId },
Line 4 - bko => new { bko.UniqueID, bko.Year, bko.BookNumber },
Line 5 - (bk, bko) => new JoinModel { Book = bk, BookOrder = bko })
Line 6 - .Where(r => r.Book.Value > 0).ToList();
你可以改變'JoinModel'? – juharr