c# - Convert SQL to LINQ: select the result into model -
i'm not familiar linq, can 1 me out? in advance.
my model:
public class orderoverviewmodel { public int quantity { get; set; } public string accn { get; set; } public datetime orderdate { get; set; } }
and sql:
select count(*) howmany, dateadd(dd, 0, datediff(dd, 0, rxs_orderdate)) orderdate, rxs_accn accn rxs_rxjobs datediff(wk, rxs_orderdate, getdate()) = 1 group rxs_accn, dateadd(dd, 0, datediff(dd, 0, rxs_orderdate))
the result in ssms:
i want select result fill model, how acchieve this? again.
use sqlfunctions.datediff method weeks between current date , order date. can date part of date via date
property of datetime
object. query should this:
from j in context.rxs_rxjobs .where(x => sqlmethods.datediffday(x.rxs_orderdate, datetime.now) >= 7 && sqlmethods.datediffday(x.rxs_orderdate, datetime.now) < 14) group j new { j.rxs_accn, j.rxs_orderdate.date } g select new orderoverviewmodel { quantity = g.count(), accn = g.key.rxs_accn, orderdate = g.key.date };
update (for linq entities):
from j in context.rxs_rxjobs .where(x => sqlfunctions.datediff("wk", x.rxs_orderdate, datetime.now) == 1) group j new { j.rxs_accn, date = entityfunctions.truncatetime(j.rxs_orderdate).value } g select new orderoverviewmodel { quantity = g.count(), accn = g.key.rxs_accn, orderdate = g.key.date };
Comments
Post a Comment