查了一下,可以用命令行生成相应的文件:
Scaffold-DbContext "Server=.\SQLExpressDatabase=SchoolDBTrusted_Connection=True" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
连接字符串放json里面
"ConnectionStrings": {
"MbkDbConstr": "Data Source=(localdb)\\MBKDatabase=MbkTest"
}
参考资料:
网页链接
查询方法public static DataSet ExecuteMySql(string strSQL)
{
//这里做些修改
MySqlConnection con = new MySqlConnection(“Host = 192.168.0.10Port = 3306User Id=rootPassword=1234Persist Security Info=TrueDatabase=smsprodb_mysql”)
MySqlDataAdapter da = new MySqlDataAdapter(你的sql语句, con)
DataSet ds = new DataSet()
da.Fill(ds)
con.Close()
return ds
}
增删改方法
public static DataSet UpdataMySql(string strSQL)
{
//这里做些修改
MySqlConnection con = new MySqlConnection(“Host = 192.168.0.10Port = 3306User Id=rootPassword=1234Persist Security Info=TrueDatabase=smsprodb_mysql”)
MySqlcommand sqlcom=new MySqlcommand ()
sqlcom.Connection=con
sqlcom.CommandString=“你的sql语句"
sqlconnect.open()
DataReader dr=sqlcom.ExecuteReader()
int x=sqlcom.ExecuteNonQuery()
con.Close();
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)