LINQ queries vs Stored procedures(LINQ 查询与存储过程)
问题描述
使用 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.
这篇关于LINQ 查询与存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:LINQ 查询与存储过程
- 在 C# 中异步处理项目队列 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- 使用 rss + c# 2022-01-01
