0
我想创建一个特定的类来管理我的应用程序中的大学生。如何在EF中为集合创建特定的类?
例如,我有一个商店,我有一个集合中的客户列表,在这个集合中,我有一个客户是本月的客户,有些客户获得了一些折扣原因。让我们来看看代码:
public class Store {
public ICollection<Customer> Customers { get; set; }
public Customer CustomerOfTheMonth
{
//get and set for customer of the month
}
public ICollection<Customer> DiscountCustomers
{
//get and set for customer of the month
}
public ICollection<Customer> GetAllCustomers
{
//get and set for customer of the month
}
}
但是在我的数据库中,我只有两个表。商店和客户。
我想要做的是为客户创建一个特定的集合,从Store中删除逻辑并放入特定的类,毕竟我不觉得这些逻辑属于这两个类。
我广域网tomething这样的:
public class Store {
internal CustomerCollection Customers { get; set; }
//get and set for the propertis, just delegating for the collection
}
public class CustomerCollection {
public ICollection<Customer> Customers { get; set; }
public ICollection<Customer> DiscountCustomers
{
//get and set for customer of the month
}
//get and set with logic to filter the collection
}
有没有去创建这个映射,并保持只有两个数据库中的表?我想让它对应用程序透明。对于代码问题抱歉,键入堆栈溢出并没有检查语法。
当我加载存储时,客户被加载在一起,我不想分开它。 – Migore
然后你可以使用急切的加载。 –