Reputation: 18802
I have a fairly standard inheritance situation in my current LINQ-to-SQL project. I have a base class called 'Party' and classes called 'Individual' and 'Organisation' which inherit from it.
What I want to achieve seems (and probably is) fairly simple. I want to return a list of 'Organisations' sorted by Company Name. The problem is that the company name ('CoName') field is a member of the 'Organisation' class, not the 'Party' class.
My current, unsorted query is...
oClients = (From P In ERM.Parties Where TypeOf (P) Is Organisation)
What I'd like to do is this...
oClients = (From P In ERM.Parties Where TypeOf (P) Is Organisation Order By CoName)
... but of course this doesn't work as the 'CoName' property isn't a member of the 'Party' class.
Any help would be greatly appreciated!
Upvotes: 0
Views: 317
Reputation: 59375
Use the OfType<>()
operator:
ERM.Parties.OfType<Organisation>().OrderBy(p => p.CoName)
Upvotes: 4