Entity framework 将接口与mvc3 EF中的类绑定

Entity framework 将接口与mvc3 EF中的类绑定,entity-framework,asp.net-mvc-3,class,interface,Entity Framework,Asp.net Mvc 3,Class,Interface,假设我有一些界面,比如: public interface IIconComponent { // statements ... } 然后我在我的类中实现这个接口,如下所示 public class IconComponent : IIconcomponent { // implementing the interface statements .. } 并在mvc3中创建一个表,如: public class IconDBContext : DbContext { pub

假设我有一些界面,比如:

public interface IIconComponent
{
   // statements ...
}
然后我在我的类中实现这个接口,如下所示

public class IconComponent : IIconcomponent
{
   // implementing the interface statements ..
}
并在mvc3中创建一个表,如:

public class IconDBContext : DbContext
{
   public DbSet<IIconComponent> Icon {get; set;} //Is this statement possible 
}
公共类IconDBContext:DbContext
{
公共数据库集图标{get;set;}//此语句可能吗
}
这就是创建接口类型的对象集,用于在表中存储类IconComponent对象。如何在MVC3中实现这一点

我是否需要为此实现一些模型绑定器?或者,还有其他方法吗


谢谢,EF不支持接口
DbSet
必须使用实际实现定义。一旦您将其更改为使用实现,您的操作很可能也会使用它,因为没有理由使用抽象。

为什么要使用实体框架是因为您正在其上创建抽象层,这是因为您根本没有使用实体框架,并且因为实体框架无法使用接口

如果确实需要,可以让实体框架类实现接口。使用POCO很简单,使用edmx可以生成包含接口派生的分部类。然而,正如Ladislav所说,类似于
DbSet
的东西是不可能的

我可以想象您希望使用此功能的场景,例如,处理仅接受特定接口但希望使用EF类填充的其他应用程序组件。(前几天,我用一个遗留UI层做到了这一点)