【发布时间】:2012-12-09 19:45:07
【问题描述】:
我正在尝试构建一组可重用的 EF 模型和接口。一个这样的接口称为ICategorised,如下所示:
public interface ICategorised {
int CategoryID { get; set; }
Category Category { get; set; }
}
Category 对象如下所示:
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; }
}
.. 并且能够以某种方式查询CategoriesType==Car 的位置。
【问题讨论】:
-
您预计会出现多少种类型?
-
最初只是一对。我的计划是使我正在编写的业务逻辑、视图等尽可能易于重用。
标签: c# entity-framework design-patterns code-first entity-framework-5