Click here to Skip to main content
Rate this: bad
good
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,
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 2-Mar-12 4:23am
Edited 2-Mar-12 4:27am
v2

1 solution

Rate this: bad
good
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)
  Permalink  

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

  Print Answers RSS
0 Kornfeld Eliyahu Peter 420
1 OriginalGriff 303
2 Yogesh Kumar Tyagi 230
3 Gihan Liyanage 99
4 sankarsan parida 90


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 2 Mar 2012
Copyright © CodeProject, 1999-2014
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