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

entity-framework-core

Question

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
2
3/20/2018 9:47:56 AM

Accepted Answer

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

2
1/14/2018 2:07:23 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow