LINQ returns repeated records

0

I have a table with the same ID in two records and it returns a single one repeated. I tried two ways and the same thing happens.

var x = db.SFI_Mix.Where(c => c.ID_Mix == id).Distinct().ToList();

and with

string sql = "SELECT * FROM SFI_MIX WHERE ID_MIX = '" + id + "'";           
var x = db.SFI_Mix.SqlQuery(sql).ToList();

If I add Distinct () it returns only one. Am I doing something wrong?

    
asked by Valentina Oppen 19.07.2017 в 19:35
source

1 answer

2

The consult would be like this:

    var x = db.SFI_Mix.Where(c => c.ID_Mix == id).ToList();

to scroll:

    foreach(var item in x)
    {
        var idMix = item.ID_Mix;
        /// los datos que quieras ver de cada fila.
    }

The Distinct is used to only show the first one that meets the comparison condition.

If it brings you one, it is that the records are identical. With the Foreach you will be able to verify it manually.

Greetings

    
answered by 22.02.2018 в 14:36