Wei Chen Chen
Wei Chen Chen

Reputation: 88

Entity Framework : how to add counter variable to its results

I have an EF query as shown here. I would need to get the list (x variable) with its counter (sequence), 1, 2, 3, 4, 5, as another column

How do I achieve it?

List<ERP_Table> x = db.ERP_Table
                      .Where(e => e.INo == currINo)
                      .DefaultIfEmpty()
                      .ToList();

Upvotes: 1

Views: 254

Answers (1)

Ming Tsai
Ming Tsai

Reputation: 36

Maybe you could use the index value on the .Select method.

List<ERP_Table> x = db.ERP_Table
                      .Where(e => e.INo == currINo)
                      .DefaultIfEmpty()
                      .AsEnumerable()
                      .Select((item, i) => new {Item: item, Index: i})
                      .ToList();

Upvotes: 1

Related Questions