Convert a LINQ statement to an SQL statement

Source: Internet
Author: User

During this time, writing of LINQ and SQL is missing! Or are you getting old? More and more will not change

Problem:

========================================================== ========

VaR ret = from X in LS
Where (
String. isnullorempty (Arg. querytext )? True:
(
(X. ?? ""). Toupper (). Contains (Arg. querytext. toupper ())
| (X. B ?? ""). Toupper (). Contains (Arg. querytext. toupper ())
| (X. c ?? ""). Toupper (). Contains (Arg. querytext. toupper ())
)
I can see this statement to understand its meaning, but I have no choice but to look forward to the answer.
========================================================== ========
The premise for this question is that this statement is a query performed in LINQ to object and cannot directly generate an SQL statement. I stared at this and did not find it for a night, I want to convert it into an SQL statement, but I find that I have regressed to a certain extent, and I do not know how to manually convert it. I ran to csdn to ask for help, but found that everyone had been to May 1.
Today, when I went out to play with my niece, I suddenly thought why I didn't switch to LINQ to SQL for testing. Both vs2010 and third-party software can be automatically converted to SQL statements, come back and implement it quickly. The result is as follows:
Select * from LS
Where
Upper (a) Like querytext or
Upper (B) Like querytext or
Upper (c) Like querytext
That's simple.
Note ):
String [] YY = new string [] {"test "};
VaR ret = from X in LS
Where (
String. isnullorempty (Arg. querytext )? True:
(
(X. ?? ""). Toupper (). Contains (Arg. querytext. toupper ())
| (X. B ?? ""). Toupper (). Contains (Arg. querytext. toupper ())
| (X. c ?? ""). Toupper (). Contains (Arg. querytext. toupper ())
& Yy. Contains (X. d)
)
The SQL statement is as follows:
Select * from LS
Where
Upper (a) Like querytext or
Upper (B) Like querytext or
Upper (c) Like querytext and
D In (@ P1)
Another little fat cat, haha:

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.