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?
Interface can contain declarations of method, properties, indexers, and events. Interface cannot include private, protected, or internal members. All the members are public by default. Interface cannot contain fields, and auto-implemented properties.
An Entity can include two types of properties: Scalar Properties and Navigation Properties. Scalar Property: The type of primitive property is called scalar properties. Each scalar property maps to a column in the database table which stores the real data.
Properties in Interfaces - Yes, since they are paired methods under the hood. I believe an interface can be declared with whatever scope you want, but all exposed functionality must be at that scope.
Interface properties typically don't have a body. The accessors indicate whether the property is read-write, read-only, or write-only. Unlike in classes and structs, declaring the accessors without a body doesn't declare an auto-implemented property.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With