问题
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