E
E
Evgeny Semashko2021-08-02 03:42:39
C++ / C#
Evgeny Semashko, 2021-08-02 03:42:39

How can a SQL statement be relayed?

In trying to relay this SQL statement to LINQ, I'm completely confused

SELECT Project.name AS Project, count(distinct Test.name) AS TEST_COUNT
FROM Project
JOIN Test ON Test.project_id = Project.id
GROUP BY Project.Name

The difficulty itself arose in the relaying of this string count(distinct Test.name)
I don’t quite understand how it can be implemented in Linq

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
V Sh., 2021-08-02
@evgenysemashko

It is possible like this:

var results1 = projects.Select(p => new
            {
                Id = p.Id,
                Name = p.Name,
                Count = tests.Where(t => t.ProjectId == p.Id).Select(x => x.Name).Distinct().Count()
            });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question