EF core Raw SQL (FromSql) query returning incorrect data?

entity-framework-core sql-server-2016

Question

I'm confused because of query which is returning different data for only one column when using a raw SQL query from Entity Framework (see the screenshot below).

The correct result is of course the one I get when querying the database directly from SQL Server.

Certainly, I'm executing exactly the same query, on the same database and on the same server. And I'm looking for the same columns.

enter image description here

EDIT: Here is the LigneFacture class:

    public class LigneFacture
{
    [Required]
    public string Entite { get; set; }
    public decimal NumFacture { get; set; }
    [Required]
    [StringLength(2)]
    public string TypeTransaction { get; set; }
    [Required]
    public DateTime DateFacture { get; set; }
    [StringLength(10)]
    public string CodeClient { get; set; }
    [StringLength(100)]
    public string NomClient { get; set; }
    [Required]
    [StringLength(10)]
    public string CodeProduit { get; set; }
    [StringLength(150)]
    public string NomProduit { get; set; }
    [StringLength(10)]
    public string CodeLabo{ get; set; }
    [StringLength(150)]
    public string Laboratoire { get; set; }
    [Required]
    [StringLength(25)]
    public string Numlot { get; set; }
    public DateTime Peremption { get; set; }
    public decimal Quantite { get; set; }
    public decimal ValeurHt { get; set; }
    public decimal ValeurRz { get; set; }
    public decimal ValeurTva { get; set; }
    public decimal PuAchat { get; set; }
    public decimal PuPpa { get; set; }
    public decimal PuDemi { get; set; }
    public decimal PuCess { get; set; }

    //This field is causing the problem (it's declared as int in the database as well)
    public int Ligne { get; set; } 

    public string HreString { get; set; }
    public int AnneeTransaction { get; set; }
    public int MoisTransaction { get; set; }
    public decimal TauxRemise { get; set; }
    public string Zone { get; set; }
    public int Colis { get; set; }

}

The rest of the values is exactly the same.

1
0
4/12/2017 10:37:18 AM

Accepted Answer

As Ivan Stoev pointed out it seems to be related the primary key of the entity being queried on.

Two rows out of three have only one different column value but the exact same primary key so it seems like the first one is returned twice.

2
4/12/2017 11:11:49 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow