我需要幫助以書面查詢,下面我寫個教學班,在這個例子中僅要緊的屬性(我還沒有數據庫表是EF生成)幫助實體框架4.1查詢
//this class will create a unique id for each location may be country,
state or city
public class Location
{
public int Id { get; set; }
public string Name { get; set; }
public string Discriminator{get;set;}
public int? ParentLocationId { get; set; }
public Location ParentLocation { get; set; }
public ICollection<Location> ChildLocations { get; set; }
}
採樣位置數據
Id | Name | Discriminator | ParentLocationId
1 | India | Country | null
2 | Karnatka | State | 1
3 | Maharashtra | State | 1
4 | Banglore | City | 2
//this will contain all product categories + products itself
public class Category
{
public int Id { get; set; }
public string Name { get; set; }
public Category ParentCategory { get; set; }
public int? ParentCategoryId { get; set; }
public ICollection<Category> ChildCategories { get; set; }
}
樣品類別的數據
Id | Name | ParentCategoryId
1 | Electronics | Null
2 | Mobiles | 1
3 | Apple | 2
4 | Nokia | 2
5 | I phone-4 | 3
6 | Nokia-Some Model | 4
我已經使用類型的在下面類變量=用戶,但我have'nt顯示「用戶」類在這裏,因爲它不包含任何東西SPL
public class Purchase
{
public int Id { get; set; }
public User User { get; set; }
[Required]
public int UserId { get; set; }
public Category Category { get; set; }
[Required]
public int CategoryId { get; set; }
public Location Location { get; set; }
[Required]
public int LocationId { get; set; }
}
注爲成功購買爲了locationId必須cityId和的categoryId應在層次是最低的,如的categoryId不能被移動,它應該是與iPhone 4或諾基亞的一些模型
SAMPL E購訂單數據
Id | CategoryId | LocationId | UserId
1 | 5 | 4 | 1
1 | 5 | 4 | 2
1 | 5 | 4 | 3
直到現在每一件事情是工作的罰款對我來說,下面是我的問題
蔭建立過濾機制,在這裏我提供兩件事情locationId(這個位置可能是國家的ID ,州或城市)和產品ID(該產品可以是任何在層次結構中的位置,例如該值可以是電子設備或移動設備或蘋果或iphone的ID)並且獲得滿足該條件的所有購買的列表
例如:樣品過濾器,我可能會
- 一>找到的狀態的所有移動出售(合格的特定狀態的移動和locationId的categoryId)
- b>查找一個國家的所有諾基亞銷售(通過一個特定國家的諾基亞和locationId的的categoryId ) 等..
我願意接受任何建議,也可以讓我知道,如果有什麼事情,這不是在這個問題得到妥善解釋。
我想你是本網站上唯一知道abt實體框架工作的人,我看到的所有EF答案,我都看到了你! –