• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 587
  • Last Modified:

sql to linq transformation

I need to change the following query to linq.  Please help

SELECT        Product_ProductServiceName, ProductClass
FROM            Table1 AS a
WHERE        (Letter = 'y') AND (Product_ProductServiceName NOT IN
                             (SELECT        ProductServiceName
                               FROM            Table2
                               WHERE        (fk_Planid = '30')))
  • 2
  • 2
1 Solution
käµfm³d 👽Commented:

var query = from a in db.Table1
            where a.Letter == "y" && !(from b in db.Table2
                                       where b.fk_Planid == "30"
                                       select o.CustomerID).Contains(a.Product_ProductServiceName)
            select new
                ProductServiceName = Product_ProductServiceName,
                ProductClass = ProductClass

Open in new window

mwhodgesAuthor Commented:
I'm using vb.net sorry.  I tried to do the conversion but I have a question where did the o .customerid come from?  Also when I get beyond the select new statment I get several other errors.  Thank you so much for your help.
käµfm³d 👽Commented:
where did the o .customerid come from?
My fault--I forgot to change that piece. Try this VB version:

Dim query = From a In db.Table1 _
            Where a.Letter = "y" AndAlso Not (From b in db.Table2 _
                                              Where b.fk_Planid = "30" _
                                              Select b.ProductServiceName).Contains(a.Product_ProductServiceName) _
            Select New With _
            { _
                a.ProductServiceName = Product_ProductServiceName, _
                a.ProductClass = ProductClass _

Open in new window

mwhodgesAuthor Commented:
Thank you so much!!  It worked perfectly

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now