Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Join and sort of two data tables
Message
 
 
To
All
General information
Forum:
ASP.NET
Category:
LINQ
Title:
Join and sort of two data tables
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01580666
Message ID:
01580666
Views:
30
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?
If it's not broken, fix it until it is.


My Blog
Next
Reply
Map
View

Click here to load this message in the networking platform