From: Armin Zingler on
Hi,

I'd like to order a query either by an Integer value or a String value.
I could write

select case condition
case 1
dim q = from bla in blub order by bla.IntegerProperty
case 2
dim q = from bla in blub order by bla.StringProperty
end select

This is of no use because I have to access q after "end select". But
if I declared it before "select case", I'd have to write

dim q as IOrderedEnumerable(Of TElement)

However, "TElement" is an anonymous type, so I can't do this also.

Is it possible to use a Comparer with the Order By clause anyhow?
Or, instead, can I achieve my goal by directly calling the extension method
System.Linq.Enumerable.OrderBy(Of TSource, TKey) anyhow?
In whichever direction I think, I always need the anonymous type. Probably
I do not and it's very simple, actually. Anybody's got a suggestion?


--
Armin



From: Vadim Rapp on
AZ> select case condition
AZ> case 1
AZ> dim q = from bla in blub order by bla.IntegerProperty
AZ> case 2
AZ> dim q = from bla in blub order by bla.StringProperty
AZ> end select

I'm not familiar with linq, but just as an idea from sql area that may be
useful here: you can do something like this in sql:

select column1 from table
order by
case
when column2='a' then column3
when column2='b' then column4
else column5
end

From: Mr. Arnold on
Armin Zingler wrote:
> Hi,
>
> I'd like to order a query either by an Integer value or a String value.
> I could write
>
> select case condition
> case 1
> dim q = from bla in blub order by bla.IntegerProperty
> case 2
> dim q = from bla in blub order by bla.StringProperty
> end select
>
> This is of no use because I have to access q after "end select". But
> if I declared it before "select case", I'd have to write
>
> dim q as IOrderedEnumerable(Of TElement)
>
> However, "TElement" is an anonymous type, so I can't do this also.
>
> Is it possible to use a Comparer with the Order By clause anyhow?
> Or, instead, can I achieve my goal by directly calling the extension method
> System.Linq.Enumerable.OrderBy(Of TSource, TKey) anyhow?
> In whichever direction I think, I always need the anonymous type. Probably
> I do not and it's very simple, actually. Anybody's got a suggestion?
>
>
> --
> Armin
>
>
>

You should pull the data 'q' with no order by

This is C# example as close as I can get it. I don't have code in front
of me.

var a = q.orderacending(b => b.Property).Tolist();


I don't know if you have Lambda statement in VB.
From: Mr. Arnold on
Armin Zingler wrote:
> Hi,
>
> I'd like to order a query either by an Integer value or a String value.
> I could write
>
> select case condition
> case 1
> dim q = from bla in blub order by bla.IntegerProperty
> case 2
> dim q = from bla in blub order by bla.StringProperty
> end select
>
> This is of no use because I have to access q after "end select". But
> if I declared it before "select case", I'd have to write
>
> dim q as IOrderedEnumerable(Of TElement)
>
> However, "TElement" is an anonymous type, so I can't do this also.
>
> Is it possible to use a Comparer with the Order By clause anyhow?
> Or, instead, can I achieve my goal by directly calling the extension method
> System.Linq.Enumerable.OrderBy(Of TSource, TKey) anyhow?
> In whichever direction I think, I always need the anonymous type. Probably
> I do not and it's very simple, actually. Anybody's got a suggestion?
>
>
> --
> Armin
>
>
>

You should pull the data 'q' with no order by

This is C# example as close as I can get it. I don't have code in front
of me.

var a = q.orderacending(b => b.Property).Tolist();


I don't know if you have Lambda statement in VB.
From: Cor Ligthert[MVP] on
> I don't know if you have Lambda statement in VB.

2010
 |  Next  |  Last
Pages: 1 2 3
Prev: database application
Next: Question on MDIchild forms