Click here to Skip to main content
11,715,450 members (78,954 online)
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 20:00pm
Edited 27-Apr-13 22:52pm
ProgramFOX164.8K
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 485
1 Richard MacCutchan 275
2 Maciej Los 259
3 ManasKumarM 155
4 Frankie-C 125
0 Sergey Alexandrovich Kryukov 785
1 CHill60 415
2 Richard MacCutchan 405
3 Maciej Los 389
4 OriginalGriff 320


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