2

i have the following SQL, how can i implement that in LINQ, i am using Entity framework in my MVC project.

  SELECT 
  * FROM Catalog.ServiceItem 
  WHERE SKU NOT IN (SELECT ServiceItemSKU FROM Catalog.TaggedServiceItems)

Any Ideas ?

EDIT: ANSWER:

var untaggedItems = from item in serviceItems where !taggedServiceItems.Contains(item.SKU) select item;

4 Answers 4

8

You can do something like this with Contains:

var result = from item in ServiceItem
    where !TaggedServiceItems.Contains(item.SKU)
    select item;
Sign up to request clarification or add additional context in comments.

Comments

1

Try this

var Catalog_ServiceItem = ds.Tables["Catalog.ServiceItem"].AsEnumerable();
var Catalog_TaggedServiceItems = ds.Tables["Catalog.TaggedServiceItems"].AsEnumerable();
var _except = from c in Catalog_ServiceItem 
                   join b in Catalog_TaggedServiceItems 
                     on c.Field<string>("ServiceItemSKU ") equals b.Field<string>("ServiceItemSKU ") into j
                   from x in j.DefaultIfEmpty()
                   where x == null
                   select c;

EDIT

You can do this

var _except = Catalog_ServiceItem.Except(Catalog_TaggedServiceItems);

1 Comment

I like using the EXCEPT, its only one line, leaves the code neat and clean . Thanks !!
0

use lambda.

dim query=Catalog.ServiceItem.where(function(q) not q.Contains(q.SKU))

Comments

-1

Try this:

var untaggedItems = 
  from i in Catalog.ServiceItem
  let taggedItems = (
    from ti = Catalog.TaggedServiceItems
    select ti.ServiceItemSKU ).Distinct()
  where ! taggedItems.Contains( i.SKU )
  select i;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.