Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Okay, so I am using linq and thus I have a few "var" types object created dynamically, as in
C#
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
C#
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,
C#
ProcessOrder
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
Updated 2-Mar-12 4:27am
v2

1 solution

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<t>, gives you all the flexibilty of a List, and also means that the result created immediately (Linq statement is not processed until used)
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900