1

示例接口:

public Interface IEntity
     Property ID() as Integer
end Interface

我希望我的所有 EF 对象都在主键上实现这个接口。

这可能吗?

4

3 回答 3

2

这在 CSharp 中似乎很容易做到,但在 VB 中,您必须明确声明哪些属性/函数/子正在实现接口:

public Property Id() as Integer Implements IEntity.Id

不幸的是,我不得不撕掉设计器文件并修改生成的属性。我最终摆脱了生成的文件,现在将我的模型保存在具有所有属性映射的单独类中。

于 2009-02-08T20:19:45.190 回答
1

是的你可以。设计器生成的类被声明为部分的。在单独的源文件中,您可以为这些类声明其他方法。您还可以声明已由生成的类实现的特定接口。

/* This is the interface that you want to have implemented. */
public interface ISomething
{
    void DoSomething();
}

/* This would be part of the generated class */
partial class PartialClass
{
    public void DoSomething()
    {
    }
}

/* This would be your own extension */
partial class PartialClass : ISomething
{
}
于 2009-02-08T17:41:01.773 回答
0

这些课程是部分的,所以应该很容易做到。

于 2009-02-08T10:51:11.430 回答