Union order in Linq to Entities?

It's because of the latter Union, you cannot guarantee order with it. You want to do this on your return: return (p1. Union(p2).

OrderByDescending(m => m. Id)) Update With further understanding of the issues, I think this will take care of it: public IQueryable GetNextPrev(Int64 photoid, string userlogin) { var p1 = (from m in db. Photos where m.Id = photoid && m.

Userlogin == userlogin orderby m. Id select m). Take(3).

Skip(0); return (p1. Union(p2). OrderBy(m => m.

Id)); }.

It's because of the latter Union, you cannot guarantee order with it. You want to do this on your return: return (p1. Union(p2).

OrderByDescending(m => m. Id)); Update With further understanding of the issues, I think this will take care of it: public IQueryable GetNextPrev(Int64 photoid, string userlogin) { var p1 = (from m in db. Photos where m.Id = photoid && m.

Userlogin == userlogin orderby m. Id select m). Take(3).

Skip(0); return (p1. Union(p2). OrderBy(m => m.

Id)); }.

If I use your solution I have next one: select number 3 - result: 9,8,7,2,1; not 5,4,3,2,1.. :( – Evgeniy Labunskiy May 3 at 14:20 Take a look at the updated answer – Adrian May 3 at 14:31 thanks for your unswer but still not. Now we have: I get #9 - the query show only number 9, but should 9,8,7. Maybe the link to project can help you to help me :). Thehe it is - test.

Wi-net.com. Ua/Photos/test. – Evgeniy Labunskiy May 3 at 14:49 @adrian, and additional problem with this proposed solution is the assumption that the ID values are contiguous.

The union approach as per the OP is the surest bet. – Ralph Shillington May 3 at 14:55 That makes sense.So it beats me why both our answers do not help... – Adrian May 3 at 14:57.

You can't assume any ordering. You always need an OrderBy if you want things ordered. Return p1.

Union(p2). OrderBy(p=> p. Id).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions