Reputation: 5866
I am trying to write the Linq version of the SQL script below. But, I couldnt do it. I couldnt do the SUBQUERY
part. T_PROJECT
and T_SERVICE_TRANSACTION
tables are linked with each other by PROJECT_ID
and P.ID
, it is a foreign key. How can I write the Linq version of it?
SELECT P.PROJECT_NAME, P.TOTAL_TIME,
(
P.TOTAL_TIME - ( SELECT SUM(GIVEN_SERVICE_TIME)
FROM T_SERVICE_TRANSACTION
WHERE PROJECT_ID=P.ID )
)
FROM T_PROJECT P
Upvotes: 2
Views: 58
Reputation: 7288
Try something along these lines..
var result = Project.Select(p => new {
ProjectName = p.ProjectName,
TotalTime = p.TotalTime,
CustomColumn = p.TotalTime - p.T_Service_Transactions
.Sum( t=> t.GivenServiceTime)
});
Upvotes: 3