Prev: database application
Next: Question on MDIchild forms
From: Armin Zingler on 6 Jan 2010 20:43 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 6 Jan 2010 23:47 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 7 Jan 2010 00:06 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 7 Jan 2010 00:09 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 7 Jan 2010 01:14
> I don't know if you have Lambda statement in VB. 2010 |