ahmed salah

ahmed salah

  • 1.2k
  • 547
  • 63.7k

How to use union statement on entity framework core instead of using s

Jul 19 2023 12:05 AM

I work on entity framework core 7 . I face issue I can't do or use union on entity framework core instead of use union on sql server

so i have view contain or return collect of unions as below

CREATE VIEW [dbo].[vDsales]
AS
SELECT        sldate, id, sdate, till, cashier, trnno, brcode, itemno, qty, price, amt, itemflag, stime
FROM            NewSaleNAV.dbo.dsales WITH (NOLOCK)
WHERE        sldate >= '2023-01-01'

UNION
SELECT        sldate, id, sdate, till, cashier, trnno, brcode, itemno, qty, price, amt, itemflag
FROM            NewSaleNAV01.dbo.dsales WITH (NOLOCK)
WHERE        sldate >= '2023-01-01'

UNION
SELECT        sldate, id, sdate, till, cashier, trnno, brcode, itemno, qty
FROM            NewSaleNAV_Arc22.dbo.dsales WITH (NOLOCK)
WHERE        sldate >= '2022-01-01'

UNION
SELECT        sldate, id, sdate, till, cashier, trnno, brcode, itemno, qty
FROM            NewSaleNAV01_Arc22.dbo.dsales WITH (NOLOCK)
WHERE        sldate >= '2022-01-01'

How to convert multi statement union to entity framework core by write statement above with LINQ to sql

my class will return data as below

public class vDsales
{
    public DateTime sldate { get; set; }
    public int id { get; set; }
    public DateTime sdate { get; set; }
    public int till { get; set; }
    public int cashier { get; set; }
    public int trnno { get; set; }
    public int brcode { get; set; }
    public int itemno { get; set; }
    public int qty { get; set; }
    public decimal price { get; set; }
    public decimal amt { get; set; }
    public int itemflag { get; set; }
    public int stime { get; set; }
}

 


Answers (1)