I have a domain model specifying the interfaces or my domain and I’m using DI to hook it up to an entity framework 4 repository implementation. In my domain I have the following:
public interface IInboundGateway : IGateway
{
ICollection<IInboundNumber> InboundNumbers { get; set; }
}
I then have my entity framework model that has generated the InboundGateway class:
public partial class InboundGateway : EntityObject
{
public EntityCollection<InboundNumber> InboundNumbers { get; set; }
}
In order to implement the IInboundGateway inteface I created a partial InboundGateway class.
public partial class InboundGateway : IInboundGateway
{
}
Eventhough EntityCollection<> implements ICollection<> and InboundNumber implements IInboundNumber I am getting an error reporting that InboundGateway does not implement interface IInboundGateway.InboundNumbers because InboundGateway.InboundNumbers does not have the matching return type ICollection<IInboundNumber>
Im pretty certain this is mental as EntityCollection does implement ICollection and InboundNumber does implement IInboundNumber.
Any help would be massively appreciated thanks.
You have to be aware that
EntityCollection<InboundNumber>is a sub type ofICollection<InboundNumber>but is NOT a subtype ofICollection<IInboundNumber>. These are 2 different types and are not related.so in the entity object class you have:
While the comopiler expects you to have:
If you could turn your EntityObjects to POCO, part of the problem would be solved since POCO classes using
ICollectionfor their navigation properties by default. Also, you need to change your interface like this: