LINQ查询对应的SQL
下面是我的SQL语句,我不能转换到LINQLINQ查询对应的SQL
select o.CustId,c.CustName,Count(o.CustId) as Total_Orders from Customer c inner join Orders o on c.CustId = o.CustId group by o.CustId,c.CustName
回答:
以下是LINQ查询(db
是的EntityFramework DBContext)。
var query = from c in db.Customers join o in db.Orders on c.CustId equals o.CustId into g
groupby new { CustID = c.CustId, CustName=c.CustName } into gs
select new { CustID = gs.Key.CustId, CustName=gs.Key.CustName, Count= gs.Count() } into gs
回答:
请尝试:
var query = from c in Customer join o in Orders
on c.CustId
equals o.CustId
group x by new {o.CustId, c.CustName}
into g
select new
{
g.Key.CustId,
g.Key.CustName,
Total_Orders = g.Count()
};
回答:
什么这样的事情?
var query = db.Customers.Select(c => new {
CustId = c.CustId,
CustName = c.CustName,
Total_Orders = db.Orders.Where(o => o.CustId == c.CustId).Count()
}
);
回答:
var query = from c in context.Customers select new
{
c.CustId,
c.CustName,
Orders = c.Orders.Count(),
};
以上是 LINQ查询对应的SQL 的全部内容, 来源链接: utcz.com/qa/257222.html