Click here to Skip to main content
10,500,000 members (77,537 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: .NET3.5 C# SQL LINQ Dynamics
Okay, so I am using linq and thus I have a few "var" types object created dynamically, as in
var Order = CustomerDataContext.Order.Where(e => e.OrderPending)
and many others like this, so the problem is how can I maintain this "var" across method calls, I am using
ThreadPool.QueueUserForWorkItem(ProcessOrder, var)
but this method accepts object and I cannot cast the back in parameter back into Order type. Also, since its dynamic it cannot even be declared as static, so that I may maintain state, so what should I do? How should I maintain this var, or if I cannot, then what is the other way to do what I am doing?

The point is, after I filter, and pass this filtered record to some other method, how do I get its same recordset or say same filtered list back, also if the method expects an argument of type object, as you cannot convert it into Order type because that var was just local variable to the caller function.

We can still create a new Order, but that would destroy the whole purpose of filtering some records and then passing those records to another method to be processed? If we create a new Order in other method say,
in this case, it will be a new Order type and not the one filtered on some condition and passed as parameter to this method. I hope I made my point clear.

Can any one help me with this?
Posted 2-Mar-12 5:23am
Edited 2-Mar-12 5:27am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Here is what I think is the solution, but cannot be sure.
The result of a linq statement is derived from type IEnumerable<T>. You can also do the following:

List<t> Order = CustomerDataContext.Order.Where(e => e.OrderPending).ToList()

This will return a type of List, gives you all the flexibilty of a List, and also means that the result created immediately (Linq statement is not processed until used)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 489
1 OriginalGriff 328
2 Mehdi Gholam 145
3 Sascha Lefèvre 135
4 KarstenK 115
0 Sergey Alexandrovich Kryukov 9,308
1 OriginalGriff 8,352
2 Sascha Lefèvre 3,334
3 Maciej Los 2,956
4 Richard Deeming 2,370

Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 2 Mar 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100