Ef core 3.0 一些要注意的改变
refer : https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/breaking-changes#dc
1. 要另外安装 nuget
Microsoft.EntityFrameworkCore.SqlServer
2. 另外装 tools
dotnet tool install --global dotnet-ef
nuget : Microsoft.EntityFrameworkCore.Design
3. FromSql, ExecuteSql, and ExecuteSqlAsync 换名字和调用了
context.Products.FromSqlRaw(
"SELECT * FROM Products WHERE Name = {0}",
product.Name);
注意 parameter 写在后面
另外一种写法是
context.Products.FromSqlInterpolated(
$"SELECT * FROM Products WHERE Name = {product.Name}");
调用的方法和方式换掉了. 但出来的结果是一样的哦.
4. FromSql 不可以在写 store procedure,
这句不合格
context.Products.FromSqlRaw("[dbo].[Ten Most Expensive Products]").FirstOrDefault();
改成这句
context.Products.FromSqlRaw("[dbo].[Ten Most Expensive Products]").AsEnumerable().FirstOrDefault();