Can I use an Interface as a property with Entity Framework?

限于喜欢 提交于 2021-02-05 04:55:35

问题


I have the following class which is a model for a database table:

public class User : IUser
{
    internal int Id { get; set; }

    public string Name { get; set; }
    public string Email { get; set; }

    public ITest TestData { get; set; }
}

When I run Update-Database command, it throws an error:

The property User.TestData is of an interface type (ITest). If it is a navigation property manually configure the relationship for this property by casting it to a mapped entity type

How and where can I manually configure the relationship for this property if I do not want the actual property to be a class?


回答1:


EF does not support interfaces, but you can deal with it this way. Take a look on this solution How to use interface properties with CodeFirst



来源:https://stackoverflow.com/questions/48250184/can-i-use-an-interface-as-a-property-with-entity-framework

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