Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How can I sort correctly?
Message
De
07/07/2017 16:42:41
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
Information générale
Forum:
C#
Catégorie:
LINQ
Divers
Thread ID:
01652557
Message ID:
01652559
Vues:
66
>Hi everybody,
>
>I wrote this code, but it has one flaw and I don't see a way to solve it:
>
>
>var items = _itemAdapter.GetAllList().Where(i => modifierGroup.ModGrpLnk.Any(m => m.ItemId == i.ItemId)).ToList();
>
>So, the modifierGroup comes with the list of ModGrpLnk entries attached to it. This ModGrpLnk class has SortOrder column. I'd like to return items belonging to the modifier group sorted according to that SortOrder.
>
>Unfortunately, I don't see a simple way of modifying the above LINQ query to return items in the right order.
>
>Do you see what can I do here?
>
>Thanks in advance.
>
>UPDATE. I think I need a JOIN query here and not the way I wrote it. I'll try to find some JOIN Linq query examples to write what I need.
>UPDATE2. Apparently I had examples of that JOIN query already, so I just used it, testing now.


-Sorting is very simple in Linq.
-If you have your primary/foreign keys and relations set in your database, then you don't need join. Joins are seldom needed with Linq,

However, your question is not understood. You are saying it comes with ModGrpLnk entries, while your Linq says it is not the case (if it is really the case then that .Any is nonsense, would mean checking a property is equal to itself).

It would look like:
.OrderBy( i => i.PropertyName)
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform