2017-04-12 68 views
0

我很困惑,因爲在使用實體框架中的原始SQL查詢(請參見下面的屏幕截圖)時,查詢只返回一列中的不同數據。EF核心原始SQL(FromSql)查詢返回不正確的數據?

正確的結果當然是直接從SQL Server查詢數據庫時得到的結果。

當然,我執行完全相同的查詢,在相同的數據庫和相同的服務器上。我正在尋找相同的專欄。

enter image description here

編輯: 這裏是LigneFacture類:

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; } 

} 

值的其餘部分是完全一樣的。

+0

什麼是'LigneFacture' - 假實體類?我們可以看到它嗎? –

+0

是的,這是一個虛假的實體類。 – iMad

+1

該「實體」的PK(我沒有看到它的定義)是什麼? –

回答

2

正如Ivan Stoev指出的那樣,它似乎與被查詢實體的主鍵相關。

三行中的兩行只有一個不同的列值,但是完全相同的主鍵,所以它看起來像第一個返回兩次。