Print Page | Close Window

Covariance in IEntityQuery<T>?

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1963
Printed Date: 13-Oct-2025 at 5:15am


Topic: Covariance in IEntityQuery<T>?
Posted By: stephenmcd1
Subject: Covariance in IEntityQuery<T>?
Date Posted: 13-Jul-2010 at 11:39am
With the move to .NET4 and it's covariance/contravariance support, I'm wondering if it would be possible to mark IEntityQuery<T> covariant?  It looks like the standard IQueryable<T> and IOrderedQueryable<T> already support covariance.

One reason I'd really like to see this is for situations like the following:

public IEntityQuery<MyBaseEntityType> GetASemiDynamicEntityQuery(bool someCriteria)
{
    if(someCriteria)
        return myEntityManager.Table1;
    else
        return myEntityManager.Table2;
}

As it stands now, the return type would have to be the non-generic IEntityQuery but then I couldn't perform further type-safe filtering or ordering, etc. on the query.

Thanks!



Replies:
Posted By: ting
Date Posted: 13-Jul-2010 at 6:47pm
Great idea.  We looked at this last year and really wanted to do it, but Silverlight does not support covariance/contravariance yet and we did not want to break the consistency of our API.



Print Page | Close Window