Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Join and sort of two data tables
Message
De
16/08/2013 16:11:12
 
 
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01580666
Message ID:
01580668
Vues:
31
This message has been marked as a message which has helped to the initial question of the thread.
Wrap the entire LINQ statement in parens then add the order by. So it would be (from ..... }).OrderyBy(...)

At least that's what I'd do.

>Hi everybody,
>
>I am wondering if I am left joining 2 data tables where the first (main table) is already correctly sorted, may I expect that the final result will be correctly sorted without a need for extra sorting?
>
>E.g. this is my current query:
>
>var resultingQuery = from instructors in dtResources.AsEnumerable()
>                                    join bookings in dtBookingInfo.AsEnumerable()
>                                    on instructors.Field<String>("resource1") equals bookings.Field<String>("resource1")
>                                    into AllInfo
>                                    from bookings in AllInfo.DefaultIfEmpty()
>                                    select new
>                                    {
>                                       resource1 = instructors.Field<String>("resource1"),
>                                       fname = instructors.Field<String>("fname"),
>                                       lname = instructors.Field<String>("lname"),
>                                       CheckedIn = instructors.Field<Boolean>("CheckedIn"),
>                                       booking_id = bookings==null?(Decimal?)null:bookings.Field<Decimal>("booking_id"),
>                                       start_time = bookings==null?(DateTime?)null:bookings.Field<DateTime?>("start_time"),
>                                       end_time = bookings == null ? (DateTime?)null : bookings.Field<DateTime?>("end_time"),
>                                       flex_tspan = bookings == null ? (Boolean?)null : bookings.Field<Boolean>("flext_tspan"),
>                                       layer = bookings == null ? (Byte?)null : bookings.Field<Byte>("layer"),
>                                       backcolor = bookings == null ? (Int32?)null:bookings.Field<Int32>("backcolor"),
>                                       forecolor = bookings == null ? (Int32?)null : bookings.Field<Int32>("forecolor"),
>                                       clip_sp = bookings == null ? (String)null : bookings.Field<String>("clip_sp"),
>                                       clip_loc = bookings == null ? (Byte?)null : bookings.Field<Byte>("clip_loc"),
>                                       display_msg = bookings == null ? (String)null : bookings.Field<String>("display_msg"),
>                                       bartype = "PVT",
>                                       locked = bookings == null ? (Boolean?)null : bookings.Field<Boolean>("locked"),
>                                       IsNotes = bookings == null ? (Boolean?)null : bookings.Field<Boolean>("IsNotes")
>                                    };
>
>My dtResources table is already sorted the way I need.
>
>I actually need to sort this differently depending on the variable prior_sort.
>
>If I do need to sort again, I am not sure where exactly should I add these OrderBy expressions in the above query?
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform