我正在嘗試構建一組可重用的EF模型和接口。一個這樣的接口被稱爲ICategorised
,看起來如下:EF接口 - 通過相關類型獲取對象
public interface ICategorised {
int CategoryID { get; set; }
Category Category { get; set; }
}
而這裏的類別對象的樣子:
public class Category {
public int CategoryID { get; set; }
public string Title { get; set; }
public Type Type { get; set; } // Is 'Type' the wrong type for this?
public string Description { get; set; }
}
我很喜歡這個原則,但我對如何略有難倒最好獲取並設置實現ICategorised
的任何對象的類型。我的最終目標是創建一個對象的能力,例如:
public class Car : ICategorised {
public int CarID { get; set; }
public string CarName { get; set; }
public int CategoryID { get; set; }
public Category Category { get; set; }
}
..並以某種方式能夠查詢Categories
哪裏Type==Car
。
您預計會發生多少種類型? –
最初只是一對夫婦。我的計劃是製作這個,我寫的商業邏輯,視圖等,儘可能容易地重用。 – Phil