ASP. NET Mvc-ef return connection pool accessing the database in ADO mode

Source: Internet
Author: User

Used to the way to access the database ADO, although the code is not written by the EF simple, but it is not troublesome. And the way EF does a multi-table query is that EF needs to go through the database to define the foreign key, then go through the code generation, and then use the Include method to make multiple table association queries. I don't really like that, but I'd rather write a SQL statement.

So the ADO can not be finished without losing. So how to combine EF and ADO.

It's very simple, as long as the connection pool of EF is returned to the SqlConnection of ADO. Then you can write it in the form of ADO.

        protected voidButton4_Click (Objectsender, EventArgs e) {            varContext =Newccxdemoentities (); SqlConnection Conn= Context. Database.connection asSqlConnection; Conn.            Open (); varcmd =(conn).            CreateCommand (); Cmd.commandtext="SELECT * from Gbook_message"; SqlDataReader Dr=cmd.            ExecuteReader (); DataTable DT=NewDataTable (); Dt. Load (DR);        }        protected voidButton5_click (Objectsender, EventArgs e) {            varContext =Newccxdemoentities (); SqlConnection Conn= Context. Database.connection asSqlConnection; Conn.            Open (); varcmd =(conn).            CreateCommand (); Cmd.commandtext="Pro_message"; Cmd.commandtype=CommandType.StoredProcedure; DataTable DT=NewDataTable (); SqlDataReader Dr=cmd.            ExecuteReader (); Dt.        Load (DR); }

ASP. NET Mvc-ef return connection pool accessing the database in ADO mode

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.