0

I'm completely new to LINQ, i want to rewrite some of mine SQL querys into LINQ (just to learn) and i'v already stuck at the beginning.

Here is SQL query :

declare @typMon varchar(200)
set @typMon = 'moneta'

select * 
from [db1].[dbo].[Picking] 
where number = 1000
and Group IN (Select grupa 
              from [db2].[dbo].[groups] 
              where typ = @typMon)

Subquery returns 3 output rows : https://i.stack.imgur.com/CDOwr.png

And here is what i'v write in LINQ

This part works ok :

var query = from x in db.grupyTowarowes
            where x.typ == typMoneta
            select new
            {
                x.grupa
            };

Problem is here:

var test = from z in dbContext.PICKINGs
           where z.Number == 1000 
           && z.group IN output from 1st query
           select new
           {
               z.id
           };
JustSomeNewbie
  • 115
  • 1
  • 11

1 Answers1

0
var test = from z in dbContext.TBL_CSV_PICKINGs 
           join g in db.grupyTowarowes on Z.group equals g.grupa
           where z.Number == 1000 && 
           g.typ == typMoneta
           select new { z.id };

Or in the Method syntax

dbContext.TBL_CSV_PICKINGs
    .Where(z => z.Number == 1000)
    .Join(db.grupyTowarowes.Where(g => g.typ == typMoneta)
        z => z.group,
        g => g.grupa,
        (z,g) => z.id);
Gilad Green
  • 36,708
  • 7
  • 61
  • 95