Entity Framework SqlQuery : how to do implement .where .orderby extend and include navigation properties?

.net c# entity-framework-6

Question

How to do paging processing for this dynamic query in Entity Framework 6 ?

BillDetailLogsDto is a custom result DTO not an database entity,how to sqlquery include navigation properties and It is impossible to pass parameters without using SqlParameter How to implement sqlquery use .Where .OrderBy extend

using (ProjectDbContext context = new ProjectDbContext())
{
    var query = context.Database.SqlQuery<BillDetailLogsDto>("SELECT *, SUM(Amount) OVER (ORDER BY Id) AS QSAmount FROM BillDetailLogs").AsQueryable();
    var result = query.Select(t => new
            {
                CustomerName = t.Customer.Name,
                t.CustomerId,
                t.Type,
                t.SortId,
                t.Amount,
                QAmount=t.QSAmount,
                t.ObjDate,
                t.OpRemark,
                t.Remark,
                t.SendOrderId,
                CreatedUserName = t.CreatedUser.RealName,
                t.CreatedDate,
            }).OrderByDescending(t => t.SortId);

    return Json(result, JsonRequestBehavior.AllowGet);
}
1
0
10/18/2019 2:32:55 AM

Popular Answer

Just add the following to your query:

.Skip(pageSize * page).Take(pageSize)
0
10/17/2019 2:00:44 PM


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