ASP. NET MVC5 -- Contains, mvc5 -- contains

Source: Internet
Author: User

ASP. NET MVC5 -- Contains, mvc5 -- contains

Preface:

* The Contains method is run on the database, not the c # code above. On the database, Contains maps to SQL LIKE, which is case insensitive.

This statement indicates that the Contains () method runs in the database, instead of the C # code. In the database, Contains is LIKE the LIKE keyword in SQL, Which is case sensitive.

I. We will add a fuzzy query for the Index page and find the Index method in the controller. The modification is as follows:

 1   public ActionResult Index(string searchString) 2         { 3             4             var movies = from m in db.Movies select m; 5  6             if (!string.IsNullOrEmpty(searchString)) 7             { 8                 movies = movies.Where(s => s.Title.Contains(searchString)); 9             }10             return View(movies);11         }

Executed

 var movies = from m in db.Movies select m;

After this code is run, the SQL statement executed by movies is:
1 SELECT   2 [Extent1].[ID] AS [ID],   3 [Extent1].[Title] AS [Title],  4 [Extent1].[ReleaseDate] AS [ReleaseDate],  5 [Extent1].[Genre] AS [Genre],    6 [Extent1].[Price] AS [Price]  7 FROM [dbo].[Movies] AS [Extent1]

After executing this sentence, the movies SQL statement is:

1 SELECT  2 [Extent1].[ID] AS [ID],    3 [Extent1].[Title] AS [Title],  4 [Extent1].[ReleaseDate] AS [ReleaseDate],   5 [Extent1].[Genre] AS [Genre],   6 [Extent1].[Price] AS [Price]  7 FROM [dbo].[Movies] AS [Extent1]  8 WHERE [Extent1].[Title] LIKE @p__linq__0 ESCAPE N'~'

As you can see, the Contains method generates the statement after Like.

 

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.