我需要帮助以书面查询,下面我写个教学班,在这个例子中仅要紧的属性(我还没有数据库表是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答案,我都看到了你! –