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