教你50招提高ASP.NET性能(二十四):ORM小窍门

ORM Tips
ORM小窍门数据库

More and more people are using Object to Relational Mapping (ORM) tools to jump the divide between application code that is object oriented and a database that is storing information in a relational manner. These tools are excellent and radically improve development speed. But, there are a few ‘gotchas’ to know about.
愈来愈多的人正在使用对象关系映射(ORM)做为越过面向对象应用程序代码和关系型存储数据库之间鸿沟的工具。这些工具很优秀从根本上提升了开发速度。可是有一些“陷阱”须要知道。服务器

 

(42)Avoid following the ‘Hello World’ examples provided with your ORM tool that turns it into an Object to Object Mapping. Database storage is not the same as objects for a reason. You should still have a relational storage design within a relational storage engine such as SQL Server.app

招数42:ide

避免按照你的ORM工具提供的‘Hello World’ 示例以致于把他变成对象到对象的映射。数据库存储和对象存储不同是有缘由的。你应该还有一个在关系型存储引擎好比:SQL Server的设计。工具

 

(43)Parameterized queries are exactly the same as stored procedures in terms of performance and memory management. Since most ORM tools can use either stored procedures or parameterized queries, be sure you’re coding to these constructs and not hard-coding values into your T-SQL queries.性能

招数43:优化

参数化查询与存储过程在性能和内存管理方面是彻底同样的。然而大多数ORM工具可使用存储过程或参数化查询,确保你根据这些结构进行编码而不要硬编码值到你的T-SQL查询中。ui

 

(44)Create, Read, Update, and Delete (CRUD) queries can all be generated from the ORM tool without the need for intervention. But, the Read queries generated are frequently very inefficient. Consider writing a stored procedure for complex Read queries.编码

招数44:设计

建立,读取,更新和删除(CRUD)查询均可以经过ORM工具生成不须要干预。可是,生成的读取查询经常是很是低效的。考虑写一个存储过程用于复杂的读取查询。

 

(45)Since the code generated from the ORM can frequently be ad hoc, ensure that the SQL Server instance has ‘Optimize for Ad Hoc’ enabled. This will store a plan stub in memory the first time a query is passed, rather than storing a full plan. This can help with memory management.

招数45:

因为从ORM生成的代码能够常常被 ad hoc,确保SQL服务器实例已经开启了‘对Ad Hoc优化’。在第一次得到查询后,将在内存中存储一个计划存根,而不是存储一个完整的计划。这样有利于内存管理。

 

(46)Be sure your code is generating a parameter size equivalent to the data type defined within table in the database. Some ORM tools size the parameter to the size of the value passed. This can lead to serious performance problems.

招数46:

确保你正在生成的代码与数据库中表数据类型定义的参数大小至关。一些ORM工具按照传输值设置参数大小。这可能会致使严重的性能问题。

相关文章
相关标签/搜索