搜索我有一個表稱爲產品和所謂的產品描述表。 ProductDescription具有一個名爲ProductDescriptionID的主鍵。所以,要獲得產品的描述,我需要訪問這兩個表。實體框架 - 通過ID
這裏是我的代碼來訪問一個產品的描述,但我不知道如何解決它,當我越來越:「lambda表達式無法轉換爲字符串,因爲它不是一個委託類型」。
productDetailsVM.ProductDescription = db.ProductDescriptions
.Where(c => c.ProductDescriptionID.Any(p => p.ProductID == id))
.FirstOrDefault();
編輯:
public partial class Product
{
public int ProductID { get; set; }
etc
}
public partial class ProductDescription
{
public int ProductDescriptionID { get; set; }
public string Description { get; set; }
}
實際上,我怎麼寫這個查詢?
你剛纔不是問同樣的問題在這裏。 http://stackoverflow.com/questions/30699816/how-should-i-write-this-entity-framework-query – deathismyfriend
沒有非常相似,但是不同的問題,第一個得到解決。另外,不同的錯誤。 – user9993
爲什麼不直接從產品開始?假設你對產品的導航性能:'productDetailsVM.ProductDescription = db.Products.Single(P => p.ProductID == ID).ProductDescription;' – DavidG