views:

17

answers:

1

I'm trying to create a data model for WCF based off of interfaces from my core object model, but I'm having trouble with some of the associations

Currently I have this in my core data model

public class A : IA {
       public string name { /* ... */ }
       public EntitySet<B> children { /* ... */ }
}
public class B : IB {
       public string name { /* ... */ }
}

However when I define the interface IA I get compiler errors saying A doesn't implement all of IA. Here is the interface

public interface IA<BType> where BType: IB  {
   string name {get; set;}
   IEnumerable<Btype> children {get;}
}

Why can't an instance of A be passed as an IA reference, given these class and interface definitions?

+1  A: 

Compilation error because public EntitySet<B> children is not implementation of IEnumerable<Btype> children {get;} (.net <4.0 version does not support covariance\contravariance)

Nagg
That's not completely correct. Co- and contravariance was added to .NET together with generics in 2.0. It wasn't supported in C# until 4.0, but .NET supported it just fine, and, e.g. Eiffel.NET uses it.
Jörg W Mittag
So you're saying this will compile in .net 4.0?
Antilogic