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
然後你可以使用急切的加載。 –