1
votes

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.

1

1 Answers

1
votes

You have to be aware that EntityCollection<InboundNumber> is a sub type of ICollection<InboundNumber> but is NOT a subtype of ICollection<IInboundNumber>. These are 2 different types and are not related.

so in the entity object class you have:

public EntityCollection<InboundNumber> InboundNumbers { get; set; }

While the comopiler expects you to have:

public ICollection<IInboundNumber> InboundNumbers { get; set; }


If you could turn your EntityObjects to POCO, part of the problem would be solved since POCO classes using ICollection for their navigation properties by default. Also, you need to change your interface like this:

public interface IInboundGateway : IGateway {
    ICollection InboundNumbers { get; set; }
}