A.Goutam
A.Goutam

Reputation: 3494

Linq not getting correct value in List

I am getting a list of object with type List and I want that records form the list which EventType = "Changed" EventDesc = "Changed" and UserName = "zMobile" But when i try to get the result with my code i am getting only one row multiple times with the same data

orderEvent = new List<ECGetOrderResponse.OrderEvent>();
EventType = "Changed";
EventDesc = "Changed";
UserName = "zMobile";
orderEvent = result.Body.Order.OrderEvents.OrderEvent;
query = orderEvent
   .Where(o => o.EventType == EventType)
   .Where(o => o.EventDesc == EventDesc)
   .Where(o=>o.UserName==UserName)
   .ToList();

One More thing i want to do in the linq code that is: the orderEvent has a property that is Notes. i want to filter only that record in which Notes Last 1 value is 'A'

can you describe what will be the correct format of the Linq statement for my result?

Upvotes: 0

Views: 112

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460058

when i try to get the result with my code i am getting only one row multiple times with the same data

With this code it's impossible to get always the same row, so result.Body.Order.OrderEvents.OrderEvent already contained these rows before. But you haven't shown what it is so we can't help to fix it.

i want the orderEvent has a property that is Notes. In the notes field last 1 character is 'A'

Well, that is easy:

query = orderEvent
   .Where(o => o.EventType == EventType)
   .Where(o => o.EventDesc == EventDesc)
   .Where(o => o.UserName  == UserName)
   .Where(o => o.Notes.EndsWith("A", StringComparison.CurrentCultureIgnoreCase)) 
   .ToList();

Change StringComparison accordingly if you don't want to allow a.

Upvotes: 3

Related Questions