using (SchoolContext dbCOntext = new SchoolContext())
{
string str = "select * from student";
System.Data.Common.DbCommand cmd = dbCOntext.Database.Connection.CreateCommand();
cmd.CommandText = str;
cmd.CommandType = CommandType.Text;
//转成sqlcommand正常查询语句。
MySql.Data.MySqlClient.MySqlDataAdapter da = new MySql.Data.MySqlClient.MySqlDataAdapter();
da.SelectCommand = cmd as MySql.Data.MySqlClient.MySqlCommand;
DataTable dt = new DataTable();
da.Fill(dt);
//List<Student> lst = (from d in dbCOntext.Students where d.StudentName == "New Student" select d).ToList();
//List<Student> lst1 = (from d in dbCOntext.Students select d).ToList();
}
根据上文EF动态新建数据库/表