ADO. NET Entity Framework: SQL statement used to check the latest row

Source: Internet
Author: User

When you use the ADO. NET Entity Framework, when you need to obtain the primary line, the SQL statement of the primary line is used.
You can use the totracestring () method in system. Data. Objects. objectquery
Example

 
01 /// Display method: SQL statement Display Method
02 using (TestEntities te = new TestEntities())
03 {
04     /// System. Data. objects must be referenced.
05     ObjectQuery oq = te.user.Where(a => a.user_id == 2) as ObjectQuery;
06   
07     /// Obtain the SQL statement using the totracestring () method
08     string sql = oq.ToTraceString();
09   
10     /// Extract the SQL statement
11     Response.Write(sql);
12 }

The results are as follows:

Select [extent1]. [user_id] as [user_id], [extent1]. [user_name] as [user_name],
[Extent1]. [user_email] as [user_email] from [DBO]. [user] as [extent1]
Where 1 = [extent1]. [user_id]

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.