entity framework - EF union and count query -


i have sql command below,how can translate ef query?

 select sum(t1)                                                                (                                select count(*) t1 products.[product] t t.txdate between '2015-06-01' , '2015-06-02'                                union                                select count(*) t1 products.[product_archive] t t.txdate between '2015-06-01' , '2015-06-02'                                union                                select count(*) t1 products.[product_cancel] t t.txdate between '2015-06-01' , '2015-06-02'                                ) m 

you can use concat extension combine results.

    var starttime = datetime.parse("2015-06-01");     var endtime = datetime.parse("2015-06-02");     var products = context.set<products>()                    .where(p => p.txdate >= starttime , p.txdate <= endtime);     var archivedproducts = context.set<productarchive>()                            .where(p => p.txdate >= starttime , p.txdate <= endtime)                            .select(ap => new products(){...});     var canceledproducts = context.set<productscancled>()                            .where(p => p.txdate >= starttime , p.txdate <= endtime)                             .select(cp => new products(){...});;      var allproducts = products.concat(archivedproducts)                       .concat(canceledproducts).tolist(); 

as can see have project each other product type same type. in case projecting archived products , canceled products product entity.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -