using linq set operators on derived classes

Apr 8, 2011 at 9:13 PM

it seems i cannot use .except linq method on a derived class

for example

I have a user class that inherits from a person class.

Dim o = Comp.Business.Objects.UserCollection.RunSelect.Except (does not compile)

while on a non inherited class (like role)   does compile

 Dim o = Comp.Business.Objects.RoleCollection.RunSelect.Except(.....) (does compile)

is this by design and is there a way to overcome a situation like this ?

Giannis

 

 

Coordinator
Apr 13, 2011 at 1:59 PM

For inherited objects sometimes the compiler gets confused. You might need explicitly declare the type. Please see below in C#. I do not know how to write it in VB.

Implicit
UserCollection.RunSelect().Except(someList);

Explicit
UserCollection.RunSelect().Except<User>(someList);

Notice that I am defining the object type for the "Except" method. This works with all LINQ methods like this.
var q = CustomerCollection.RunSelect();
var i = q.FirstOrDefault<Customer>(); 

Apr 14, 2011 at 7:36 PM

well i tried it in both vb.net and c# environment.

(vs 2008  .net 3.5)

In c# it does compile as shown in example

but in vb.net the same code does not compile.

So it must be one of those c# to vb.net incompatibilities.

Don't know if it is resolved in .net framework 4.0 .

Hope it is .

Giannis

 

Coordinator
Apr 14, 2011 at 8:50 PM

The syntax is different I am sure. There is some way to explicitly specify the object type I know in VB.