Entity Framework: Extending partial class with interface without touching the EF-generated classes

点点圈 提交于 2019-12-11 03:43:18

问题


My problem is similar to this post: Interface inheritance in Entity Framework

Thus, I copy that example and modify it for my issue:

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; }
}


What I would like to do is the following:

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

But then I get the following errors:

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

Obviously I can see that, too.
But I thought that after compiling, the partial classes will become one, so that the compiler should not complain.

Any ideas?

Thanks in advance!


回答1:


I had the same error, and i resolved moving partial class outside App_Code folder! I should admit that i don't understand the reason :-(



来源:https://stackoverflow.com/questions/16057349/entity-framework-extending-partial-class-with-interface-without-touching-the-ef

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!