我想在实体框架中使用 SQL 查询。
这是我的代码:
string sql = (@"SELECT G.GainId,
(SELECT Name FROM Carrier WHERE CarrierId = G.CarrierId) AS Carrier,
(SELECT Name + ' ' + Surname FROM [User] WHERE UserId = G.GainerId) AS Gainer,
(SELECT Name + ' ' + Surname FROM [User] WHERE UserId = G.GiverId) AS Giver,
(SELECT Name + ' ' + Surname FROM [User] WHERE UserId = G.CustomerId) AS Customer,
P.Name,
G.Gained,
G.Paid
FROM Gain AS G
INNER JOIN Product AS P ON P.ProductId = G.ProductId");
DataTable tbl = _context.Database.SqlQuery<DataTable>(sql) as DataTable;
但tbl
为空。你有什么建议吗?我是实体框架的新手。