2

我的问题类似于这篇文章: 实体框架中的接口继承

因此,我复制了该示例并针对我的问题对其进行了修改:

public interface IBaseEntity
{
    DateTime CreatedOn { get; set; }
    string CreatedBy { get; set; }
}

// The following two classes are generated by Entity Framework
public partial class SomeEntity
{
    public int SomeEntityId { get; }
    public string Name { get; set; }
    public DateTime CreatedOn { get; set; }
    public string CreatedBy { get; set; }
}

public partial class OtherEntity
{
    public int OtherEntityId { get; }
    public float Amount { get; set; }
    public DateTime CreatedOn { get; set; }
    public string CreatedBy { get; set; }
}


我想做的是以下几点:

public partial class SomeEntity : IBaseEntity
    {
        // No code needed here because the other partial class
        // already has the needed properties
    }

但后来我收到以下错误:

Error 64 '[...].SomeEntity' does not implement interface member '[...]IBaseEntity.CreatedOn'
Error 64 '[...].SomeEntity' does not implement interface member '[...]IBaseEntity.CreatedBy'

显然,我也可以看到这一点。
但是我认为编译后,部分类会合二为一,这样编译器就不要抱怨了。

有任何想法吗?

提前致谢!

4

1 回答 1

-1

我遇到了同样的错误,我解决了将部分类移到 App_Code 文件夹之外的问题!我应该承认我不明白原因:-(

于 2016-05-29T20:08:01.690 回答