c# – 如何加载实体框架预编译视图
发布时间:2020-12-15 21:35:33 所属栏目:百科 来源:网络整理
导读:我发现通过使用EdmGen.exe工具预编译我的视图,我可以提高应用程序的性能. 这一切都很好,但我或我的大学都无法确定项目实际使用生成的.cs文件的方式. 似乎没有任何关于在任何地方生成的类的引用,所以如何包含它? 任何人都可以对此有所了解,因为它真的很令人
我发现通过使用EdmGen.exe工具预编译我的视图,我可以提高应用程序的性能.
这一切都很好,但我或我的大学都无法确定项目实际使用生成的.cs文件的方式. 任何人都可以对此有所了解,因为它真的很令人沮丧,不知道它是如何工作的! 编辑 我们已经确认EntityViewGenerationAttribute用于标记预编译视图的类类型,但这必须意味着它通过反射加载. 解决方法
您可以尝试更改生成的代码.这样就返回了一个不同的视图.
但是如果你不返回视图,我希望EF会失败. 我们的想法是生成的类适用于DBContext中的所有集合.事实上,如果视图与您拥有的上下文(哈希比较)不匹配,您将收到运行时错误. 例如 /// <Summary> /// The constructor stores the views for the extents and also the hash values generated based on the metadata and mapping closure and views. /// </Summary> public ViewsForBaseEntitySets24F9763E92A9F77E970A08557E1855C7579989F684539A5FB429069F966B9B7B() { this.EdmEntityContainerName = "Ef6Ctx3"; this.StoreEntityContainerName = "CodeFirstDatabase"; this.HashOverMappingClosure = "d7686982aa7cffcf874313838914e93f78d4d7d6d345d19261ef5edc8b4e96dd"; this.HashOverAllExtentViews = "7b8857ee3ee44d13b2479e43c54dbdfb6bc8914e222c7891afcfcd9a29b06b2f"; this.ViewCount = 2; } 但是对于给定的视图,您可以返回不同的字符串 /// <Summary> /// return view for CodeFirstDatabase.pocotest /// </Summary> private System.Collections.Generic.KeyValuePair<string,string> GetView0() { return new System.Collections.Generic.KeyValuePair<string,string>("CodeFirstDatabase.pocotest",@" SELECT VALUE -- Constructing pocotest [CodeFirstDatabaseSchema.pocotest](T1.pocotest_Id,T1.pocotest_f1,T1.pocotest_f2,T1.pocotest_f2a,T1.pocotest_f3,T1.pocotest_f5,T1.pocotest_f6b) FROM ( SELECT T.Id AS pocotest_Id,T.f1 AS pocotest_f1,T.f2 AS pocotest_f2,T.f2a AS pocotest_f2a,T.f3 AS pocotest_f3,T.f5 AS pocotest_f5,T.f6b AS pocotest_f6b,True AS _from0 FROM Ef6Ctx3.poco1s AS T ) AS T1"); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 将非常大的int(写成字符串)转换为c / c中的二进制字符串
- PostgreSQL 数据迁移 (从Mysql到Postgres)
- 为什么在C#中没有System.DateTime的“日期”缩写?
- flex 入门学习笔记2 之popupbutten的使用
- postgresql – 如何删除postgres中的枚举类型值?
- c 11 std :: thread用函数编译,但不编译
- Oracle cursor in sqlplus, and optimizer hints
- ruby-on-rails – 如何配置Rails在引发弃用警告时引发错误?
- 在使用Visual C构建时,如何使用SSE(和SSE2,SSE3等)扩展?
- org.xml.sax.SAXParseException: An invalid XML character