在我正在開發的項目中,我有一個數據庫(我無法修改)使用兩個表(Item和ItemSupplier)。 db中沒有外鍵。在我的EF6我已經創建了兩個對象(數據庫在前):獲取基於Linq的其他集合的屬性的集合
public class Item {
public string ItemCode { get; set;}
public string Description { get; set; }
public double SalesPrice { get; set; }
}
public class ItemSupplier {
public string ItemCode { get; set; }
public string AccountCode { get; set; }
}
我想是屬於特定供應商的Item
列表。所以我的想法是首先得到的ItemSupplier
列表,然後開始使用Any()
的Item
列表:
public List<Item> GetItemsByAccountCode(string code)
{
List<Item> itemList = new List<Item>();
using(DbEntities context = new DbEntities())
{
// Get the list of items of a specific supplier
List<ItemSupplier> itemSupList = context.ItemSupplier.Where(p =>
p.AccountCode == code).ToList();
// Get al the items based on the itemSupList
// Below is not working
itemList = context.Item.Where(p => itemSupList.Any(x => x.ItemCode));
}
}