Entity SQL 还是 StoredProcedure,该用什么?
我可以选择在 DAL 中使用Entity SQL 查询,或者在 db 级别使用存储过程作为选项。
我应该使用哪一个。这两种方法的优点/缺点是什么?
我更倾向于Entity SQL,因为我不希望我的逻辑以任何形式的数据库级别暴露。
I have got choice for using either Entity SQL query inside my DAL or use Stored Procedure at db level as a option.
Which one should I use. And what are the benefits/drawbacks for either approach?
I am more inclined towards Entity SQL as I don't want my any form of db level exposure of my logic.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据我的经验:
实体框架:
需要知道列的顺序等等......
数据库 SP
就我个人而言,我也会使用 EF,因为我已经上面提到的(加上我现在想不起来的其他一些)。此外,如果我无法使用 linq 查询执行或无法快速执行某些操作,我将仅创建一个存储过程或仅执行一条 SQL 语句(是的,您可以使用上下文执行 SQL)。
Based on my experience:
Entity Framework:
need to know the order of the columns and such..
Database SPs
Personally, I'd go with EF too for the reasons I've mentioned above (plus a few others I cant think of right now). Besides, if there's something I can't do or cant do fast with a linq query, I'll just create a stored proc or just execute an SQL statement (yes you can execute SQL using the context).
如果您也是数据库管理员,请使用 LINQ 实体。
如果将代码放在一起会更容易。
但是,如果您熟悉 SQL(或者其他人负责 SQL Server 性能),则可以使用存储过程。无需重新发布应用程序即可更轻松地优化数据库操作。
If you are the DB administrator as well, then use LINQ Entities.
It's easier if you keep your code together.
However, if you know your way around SQL (or someone else is in charge of SQL Server Performance), then use Stored Procedures. It's much easier to optimize your DB operations without re-releasing your application.
两者都有自己的优点和缺点。
Entity SQL 始终参数化,因此可以免受 SQL 注入攻击。
但如果您足够了解 SQL,您会发现存储过程会更加谨慎。
您知道可以在实体框架中使用存储过程吗?
更愿意建议实体框架。当您觉得在特定场景中存储过程更加优化时,请使用存储过程。
Both are having its own pros and cons.
Entity SQL is secure from SQL injection attacks as its always parameterized.
But if you know SQL well enough, you would see cases where a Stored Procedure would be more prudent.
Do you know that you can use Stored Procedures in Entity Framework?
Would prefer suggesting Entity Framework. Use Stored Procedures when you feel in a particular scenario Stored Procedures are more optimized.
我仅在以下情况下使用 StoredProc:
I use StoredProc only if: