编辑:
这个问题不是关于编译查询,而是关于在编译时生成 EF 数据库 View 。
来自 ADO.NET 团队博客:Exploring the Performance of the ADO.NET Entity Framework - Part 1 :
View Generation 56%– A big part of creating an abstracted view of the database is providing the actual view for queries and updates in the store’s native language. During this step, the store views are created. The good news is there is a way of making view generation part of the build process so that this step can be avoided at run time.
我的 Web 应用程序中的第一个数据库调用大约需要 2.5 秒,而不是后续相同调用的大约 30 毫秒。
我使用 ADO.NET team blog 中的 T4 模板生成了一个预编译 View 源文件, 但它没有产生明显的差异。
T4 模板需要大约 2.5 秒的时间来运行并编译生成的代码。
我错过了什么?
最佳答案
已修复!
从 EntityViewContainer 派生的生成 View 必须位于包含 STO self 跟踪对象的程序集中,而不是包含 edmx 模型的程序集中。
关于c# - 预编译 View 不影响性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8272461/