LINQ 查询与存储过程
- 作者: 禽兽的忏悔-_-
- 来源: 51数据库
- 2022-12-13
问题描述
使用 linq 查询(以及像 EF 或 linq2sql 这样的 ORM)VS 的优缺点是什么.存储过程(SQL server 2008)查询和更新数据模型?表现?速度?等等……
What are the pros and cons of using linq queries(along with an ORM like EF or linq2sql) VS. Stored Procedures(SQL server 2008) to query and update a data model? Performance? Speed? Etc...
推荐答案
当您在代码中时,Linq 绝对更具可读性.作为开发人员,看到执行名为sp_GetSomething"的 sproc 的调用并不会告诉您任何事情,除非您亲自查看 sproc 的作用.看到像
Linq is definitely more readable when you're in the code. Seeing a call to execute a sproc called "sp_GetSomething" doesn't tell you anything as a developer, unless you go and physically look at what the sproc does. seeing code like
var query = from c in db.TableName
where c.Name == "foo"
select c;
这会告诉您正在提取哪些数据.
That tells you exactly what data is being pulled.
另一方面,如果您决定更改代码,存储过程不需要您重新编译应用程序.如果您决定突然更改where"子句或更改Order By - 更改 sproc 很容易.更改 Linq 代码可能更耗时.
Stored procedures on the other hand do not require you to recompile the application if you decide to change the code. If you decide to suddenly change a "where" clause or change the Order By - changing a sproc is easy. Changing the Linq code could be more time consuming.
我确定还有很多,但我注意到了这两个.
I'm sure there are plenty more, but these are two I've noticed.
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
