One: Executes the SQL statement, returning the number of rows affected
In MySQL, if there is no effect, then the number of rows returned is-1, SQL Server has not been tested
Usingnew Mydbcontext ()) { ctx. Database.executesqlcommand ("UPDATE person SET Name = ' Michael ' WHERE PersonID = 1");}
Two: database.sqlquery<t> EF5 Execute SQL query statement database.sqlquery with return value
This is exactly the ienumerable<t> sqlquery<t> (String sql, params object[] parameters), note that the return value is IEnumerable
This is the Execute SQL statement that returns the list of types you want
dbmain.database.sqlquery<int> ("select Max (UserId) from Tb_user_account"). First ();
Or if you have a category of your own,
publicclass personview{public intgetset;} Public string Get set; }}
Then you can return directly to the Personview class.
Usingnew Mydbcontext ()) { var peopleviews = ctx. Sqlquery<personview> ("select PersonID, Namefrom person"). ToList ();}
Return directly to the data you want. For example, here is the list<personview> list