Search code examples
c#sqllinqsql-to-linq-conversion

I need help to Convert a SQL Statement to C# LINQ


I need help with Converting this Select statement in LINQ C# Code

SELECT TagName 
from Tags 
Where TagId IN(
    SELECT TagId 
    from PresentationTags 
    Where PresentationId = 2
)

Solution

  • Where() with nested Any() should do the job

    context.Tags.Where(
        x => context.PresentationTags.Any(
            y => y.PresentationId == 2 && x.TagId == y.TagId
        )
    ).Select(x => x.TagName);