Entity Framework で 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
ヌルです。何か提案はありますか?私はEntity Frameworkが初めてです。