Tips for generating not in statements using LINQ to SQL

Source: Internet
Author: User

I used to think that the SQL statements like where id not in (1, 3, 5) or where id not in (select ID from...) are generated by LINQ to SQL ...) this condition is not very convenient. Every time I get the condition ID in an array, and then use it! When arr. Contains (C. ID) is processed like this, we suddenly find it silly today. In fact, we can directly write a sentence using LINQ, and paste an example here for future reference.

From a in tablea where! (From B in tableb where... select B. ID). Contains (A. ID)

The final translated statement is not exactly the same as not in. Instead, it uses not exists (...). However, the effect is the same, and it can meet the requirements.

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.