[Solution for Converting Method "Boolean contains (system. guid)" to SQL]

Source: Internet
Author: User
Guid CLSID =   New GUID ( " D4ee9c52-8d68-4f33-9485-0926281c78ac " );
Ilist < Guid > IDS = Webproduct. getallchildbyid (CLSID );
VaR Query = DB. t_products.where (P => IDs. Contains (guid) p. f_clsid )); // This statement has no errors during compilation, but an error is reported when it is executed.

The error message is as follows:
The "Boolean contains (system. guid)" method does not support SQL conversion.

It is estimated that. Net's existing LINQ to SQL cannot directly translate the contains method of some types of ilist (such as guid type) into SQL statements.


After studying for a long time, I accidentally found that one of the 100 official examples of LINQ uses arrays to implement in statements and also uses contains, so I switched the ilist <guid> to the guid [] array and tried it. The operation was successful.

VaR query = dB. t_products.where (P =>IDs.Contains (guid) p. f_clsid ));

Changed:

VaR query = dB. t_products.where (P =>IDs. toarray <guid> ().Contains (guid) p. f_clsid ));

In this way, you can get the result normally.

Please indicate the source of the post (net name: Yang Guo/real name: Yang junming MSN: yjmyzy@hotmail.com under the bodhi tree)

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.