oftype

Linq2SQL inherited types and OfType query

Hi I have a setup where I used Linq2SQL inheritance. To make queries easier, I expose the derived types in the DataContext as well, like the following: public IQueryable<Derived> Derivations { get { return Bases.OfType<Derived>(); } // filter list on type } Calling this works perfectly, and I can see the SQL being correctly genera...

.Net Use Reflection To Define OfType

I am using System.Reflection to load a type that I cannot otherwise load during design time. I need to pull all controls within a collection of this type, however, i the OfType command doesn't seem to like the reflection Syntax. here is "close to" what I got. Dim ControlType As Type = System.Reflection.Assembly.GetAssembly( _ ...

LINQ: From a list of type T, retrieve only objects of a certain subclass S

Given a simple inheritance hierarchy: Person -> Student, Teacher, Staff Say I have a list of Persons, L. In that list are some Students, Teachers, and Staff. Using LINQ and C#, is there a way I could write a method that could retrieve only a particular type of person? I know I can do something like: var peopleIWant = L.OfType< Teache...

How Does Queryable.OfType Work?

Important The question is not "What does Queryable.OfType do, it's "how does the code I see there accomplish that?" Reflecting on Queryable.OfType, I see (after some cleanup): public static IQueryable<TResult> OfType<TResult>(this IQueryable source) { return (IQueryable<TResult>)source.Provider.CreateQuery( ...

Find all child controls of specific type using Enumerable.OfType<T>() or LINQ

Existed MyControl1.Controls.OfType<RadioButton>() searches only thru initial collection and do not enters to children. Is it possible to find all child controls of specific type using Enumerable.OfType<T>() or LINQ without writing own recursive method? Like this. ...

Filtering derived classes in Entity set by OfType and getting exception.

Hello everybody I am trying to filter derived classes in my entities but i am getting exception. var filtered = db.PersonSet.OfType<Person>(). Where(person =>person.GetType()==typeof(Person)) I am getting below exception if i try to loop filtered collection by foreach. "LINQ to Entities does not recognize the method '...

Linq - OfType<> not working as expected

I have the following code which detects all the elements in a Silverlight application beneath a certain point then filters them to be only those of a particular type - CardButton IEnumerable<UIElement> elementsBeneathCursor = VisualTreeHelper.FindElementsInHostCoordinates(new Point(xPosn, yPosn), Application.Current.Roo...