I have two interface:
public interface IPerson
{
public string FirstName { get; set; }
public string LastName { get; set; }
public ILocation LocationOfBirth { get; set; }
}
public interface ILocation
{
public double Latitude { get; set; }
public double Longitude { get; set; }
}
Now I want to implement them like this:
public class Location : ILocation
{
public double Latitude { get; set; }
public double Longitude { get; set; }
}
public class Person : IPerson
{
public string FirstName { get; set; }
public string LastName { get; set; }
public Location LocationOfBirth { get; set; }
}
But c# is angry on me:
Property 'LocationOfBirth' cannot implement property from interface 'IPerson'. Type should be 'ILocation'.
Why is this so when Location fulfills the all requirements of ILocation?
I want to use Person as a model for EntityFramework, so I cannot use ILocation. What to do?
Edit: In my application, the implementations of the interfaces are not in the scope of the interfaces, so I cannot define IPerson with the Location implementation.
set;from the properties in your interfaces (keep them in your implementing classes).ILocationonLocationOfBirthproperty in your Person class, there's no way around that as the types have to match the interface exactly. This shouldn't be an issue with entity framework though since Location implements ILocation.