Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: LINQ C#4.0
Hi,
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();
  DeleteData(0,e);
  LstAll.Add(e);
}
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]
Posted 25-Apr-13 21:00pm
Edited 27-Apr-13 23:52pm
v3
Comments
Pheonyx at 26-Apr-13 5:45am
   
What is the error?
rohit24c at 26-Apr-13 6:26am
   
its syntactically wrong.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The solution here:
Linq Query - Call Method.[^]
 
might solve your issue.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You have 2 operations to perform, fill list and delete record, both cannot be done.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
 
Cheers
Andi
 
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 ...);
  Permalink  
v2

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 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 28 Apr 2013
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