Click here to Skip to main content
15,605,787 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a List<data> which i am trying to loop and pass it to some function.
IEnumerable<EntityObject> Data  = entity.get();
LstAll = new Employee(); 
foreach (EntityObject o in Data)
  Employee e = new Employee();

now i want to use lamba expression so that i can remove the Foreach loop and call the DeleteData.
LstAll.Add(from o in Data  
           let c = DeleteData(o,Employee e));

This code is giving me error.
Any suggestion Plz help.

[Edit: Code block added]
Updated 27-Apr-13 22:52pm
Pheonyx 26-Apr-13 5:45am    
What is the error?
rohit24c 26-Apr-13 6:26am    
its syntactically wrong.

Each Linq expression must have a select.
from ... in ... select ...;

Your example data is incomplete or maybe wrong. You talk about List<data> but this is nowhere visible in your code.
Your LstAll seems to be a list (you call Add(...) in the loop), but initialization is by a single element (new Employee() is not likely to be a list, right?).

Please revise your question and carefully check the code in the question so it exactly matches what you have in your homework assignment.


PS: What does DeleteData(...) doing? If it removes some item from the list it loops over, the program is broken.
PPS: If the problem is to add a range of elements to a list, then use the AddRange(...) method.
PPPS: Is this a typo or don't you understand where to use/don't use type names (see Employee):
LstAll.AddRange(from o in Data let c = DeleteData(o,Employee e) ... select ...);
or is it rather the following?
LstAll.AddRange(from o in Data let c = DeleteData(o, new Employee()) ... select ...);
Share this answer
You have 2 operations to perform, fill list and delete record, both cannot be done.
Share this answer
The solution here:
Linq Query - Call Method.[^]

might solve your issue.
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