gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 17:03:20 26 4
gpt4 key购买 nike

我的问题类似于这篇文章: Interface inheritance in Entity Framework

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

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'

显然我也能看到这一点。
但是我想编译之后分部类会合二为一,这样编译器就不会报错了。

有什么想法吗?

提前致谢!

最佳答案

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

关于c# - Entity Framework : Extending partial class with interface without touching the EF-generated classes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16057349/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com