教你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工具按照傳輸值設置參數大小。這可能會致使嚴重的性能問題。

相關文章
相關標籤/搜索