Answer the question
In order to leave comments, you need to log in
How to relay SQL statement data?
I wrote two such SQL statements, and when I tried to translate them into LINQ, I realized that I was a little weak in LINQ
1.
SELECT Project.name, Test.name
FROM Project
JOIN Test ON Test.project_id = Project.id
WHERE(Test.project_id = Project.id) AND (Test.start_time > '2015-11-07 00:00:00')
ORDER BY Project.name, Test.name ASC
SELECT SUM(if(Test.browser = 'chrome', 1, 0)) AS Count
FROM Test
UNION SELECT SUM(if(Test.browser = 'firefox', 1, 0)) AS Count FROM Test
var query = db.Projects.Join(db.Tests,
p => p.Id,
t => t.ProjectId,
(p, t) => new
{
Project = p.Name,
Test = db.Tests.Where(t => t.ProjectId == p.Id).FirstOrDefault(t => t.StartTime > new DateTime(2015, 11, 7)).Name
});
IQueryable
and in Runtime it throws an exception SELECT `p`.`name` AS `Project`, (
SELECT `t`.`name`
FROM `test` AS `t`
WHERE (`t`.`project_id` = `p`.`id`) AND (`t`.`start_time` > '2015-11-07 00:00:00')
LIMIT 1) AS `Test`
FROM `project` AS `p`
INNER JOIN `test` AS `t0` ON `p`.`id` = `t0`.`project_id`
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question