Covert sql to entity framework

Esteban Peralta 26 Reputation points

I have this working SQL query:

FROM Events
WHERE Events.Id NOT IN (SELECT Results.EventId
FROM Results
WHERE Results.UserId = 86);

I'm new to entity framework, so what would be it's equivalent?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,078 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,476 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,488 questions
0 comments No comments
{count} votes

Accepted answer
  1. P a u l 10,406 Reputation points

    You should be able to do something like this:

        .Where(e => !db.Results
            .Where(r => r.UserId =  86)
            .Select(r => r.EventId)

    EF will turn that inner query to the equivalent sub-query in SQL.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful