user968441
user968441

Reputation: 1471

Linq query returning same row 12 times

Hi i have written one linq query to fetch records from entity model. I am getting perfect number of records but all are same. here is my query

Entities.TEST.Where(a => a.ID.ToUpper().Equals(ID.ToUpper())).OrderBy(s => s.NAME).ToList();

Am I missing something?

Upvotes: 4

Views: 2040

Answers (3)

Laszlo Boke
Laszlo Boke

Reputation: 1329

Your query should work, i have a similar sample that works for northwind DB:

        var ctx = new NorthwindEntities();
        var emp = ctx.Employees.Where(e => e.TitleOfCourtesy.Equals("ms.", StringComparison.OrdinalIgnoreCase)).OrderBy(n => n.FirstName).ToList();

Please check your query in LinqPad. You will see the results and the generated SQL.

Upvotes: 0

Aducci
Aducci

Reputation: 26694

You need to make sure your Entity Key in your Entity Data Model is unique.

So in your example, ID should be the entity key for your Test entity

Upvotes: 7

Feanor
Feanor

Reputation: 3690

Replace Equals with == and you can go

Upvotes: -2

Related Questions