当上下文位于与域类不同的项目中时,应首先在哪个程序集中放置实体框架代码的已编译视图 [英] Which assembly should I place the compiled views for entity framework code first when context is in a separate project from the domain classes

查看:120
本文介绍了当上下文位于与域类不同的项目中时,应首先在哪个程序集中放置实体框架代码的已编译视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

迫切需要帮助.

我首先使用实体​​框架代码,并尝试遵循Julie Lerman关于从域类中突破上下文的建议,但我无法使实体框架识别已编译的视图.我已经尝试了很多方法,但到目前为止,最好的方法是可以调用已编译视图的构造函数,但是第一次查询仍需要15分钟(大约创建329个实体和600多个视图).这使我认为仍然必须在第一个查询上创建视图.

I'm using entity framework code first and trying to follow Julie Lerman's suggestion about breaking out the context from the domain classes and I'm unable to get entity framework to recognize the compiled views. I've tried many things but the best so far is that I can get the constructor of the compiled views to be called but it still takes about 15 mins for the 1st query (about 329 entities and 600+ views created). This makes me think it is still having to create the views on the 1st query.

步骤

  1. 使用现有数据库和模型项目"运行实体电源 使用工具Beta 3先进行反向工程师编码"数据库.这创造了 上下文,领域类和映射(流利)类.仅供参考,我这样做是因为 我已经对T4模板进行了一些修改,以使其符合我们的编码标准.

  1. Using an existing database and a "Model project" I ran the Entity Power Tools Beta 3 to "Reverse Engineer Code First" the database. This created the context, domain classes and mapping (fluent) classes. FYI, I do this because I have modified the T4 template slightly to match our coding standard.

使用Julie Lerman在她的多个站点培训中的建议 视频,我介绍了域类,上下文和映射类 分为3个独立的项目(上下文,领域类,映射).一世 将文件分别从模型项目复制到这3个项目中,然后将名称空间更改为与项目名称和位置相对应. 4个项目的结果和名称空间:"MyCompany.DataContext","MyCompany.DomainClasses","MyCompany.DomainMappings","MyCompany.Model".

Using Julie Lerman's recommendations from her Plural Site training videos, I broke out the domain classes, contexts and mapping classes into 3 separate projects (context, domain classes, mappings). I copied the files from the model project into these 3 projects respectively and then changed the namespace to correspond to the project name and location. The results and namespaces for the 4 projects: "MyCompany.DataContext", "MyCompany.DomainClasses", "MyCompany.DomainMappings", "MyCompany.Model".

使用模型项目"和从实体生成的代码 电动工具我选择了创建的上下文文件,然后按了鼠标右键 按钮以显示上下文菜单,由此我可以选择生成 视图".执行此操作时会出现错误序列不包含 匹配元素".(问题1)

Using the "model project" and the code generated from the Entity Power Tools I selected the context file created and pressed the right mouse button to display the context menu whereby I could select "Generate Views". When I do this it gives me an error "Sequence contains no matching element". (Problem #1)

好,因此无法正常工作,因此我通过"Pawel"添加了一个T4模板 Kadluczka"添加到"MyCompany.DataContext"项目中 视图并运行该自定义工具并获得成功,这些视图已创建 没有错误.但是,当我运行测试应用程序进行基本操作时 查询,第一个查询需要15分钟,构造函数 生成的视图的"ViewsForBaseEntitySets1B04A ... 0F8A()" 不会被打电话.

Ok, so that didn't work so then I added a T4 template by "Pawel Kadluczka" to the "MyCompany.DataContext" project for generating views and ran that custom tool and success, the views were created without error. However when I run my test application to do a basic query, the 1st query takes 15 mins and the constructor "ViewsForBaseEntitySets1B04A...0F8A()" of the generated views does not get called.

好,所以那也不起作用,所以我添加了创建的"views"文件 通过T4模板进入"MyCompany.DomainClasses"项目,以便 它将与类一起编译并运行测试 再次申请.这次,第一个查询仍然需要15分钟,但 在启动构造函数后约20秒内 调用了"ViewsForBaseEntitySets1B04A ... 0F8A()".这是进步 但没有香蕉.这使我认为这些意见必须在 与域类(而不是上下文)相同的程序集. 问题:这是一个正确的假设吗?此外,由于仍然需要15分钟,因此就像Entity Framework看到了视图一样,但是 没有 喜欢它们,所以它再次重新创建了它们. 可能吗?

Ok, so that didn't work either so I added the "views" file created by the T4 template into the "MyCompany.DomainClasses" project so that it will get compiled with the classes and ran the test application again. This time, the 1st query still took 15 mins but within about 20 seconds of starting the constructor "ViewsForBaseEntitySets1B04A...0F8A()" was called. This is progress but no banana. This makes me think that the views must be in the same assembly as the domain classes instead of the context. Question: Is this a correct assumption? Also, since it still took 15 mins, it was like Entity Framework saw the views but didn't like them so it recreated them again. Possible?

现在呢?我很茫然,一直在撞墙.如何在分解项目的多个上下文中创建预编译视图?意见去哪儿了?是否有我未遵循的命名空间规则?当我有2个或更多上下文时会发生什么?

Now what? I'm at a loss and have been beating my head against the wall. How do I create precompiled views with multiple contexts where I have the projects broken out? Where do the views go? Is there a namespace rule that I'm not following? What happens when I have 2 or more contexts?

请帮助. 公元前

推荐答案

已解决.看来,无论上下文的程序集如何,预编译的视图都必须与域类在同一程序集中.

Resolved. It appears that regardless of the context's assembly, the precompiled views must be in the same assembly as the domain classes.

另外,导致我的问题的最终原因是,我有另一个实际使用的上下文,而不是实例化的上下文.我没有意识到这两个上下文都已实例化,但是第二个上下文实际上是被调用的,并且由于我没有为其创建编译视图,因此每次运行测试应用程序都需要花费很长时间.现在,初始查询是18秒而不是15分钟,因为我将第二个上下文与新编译的视图一起使用.

Also, the ultimate cause of my problem was that I had another context that was actually being used instead of the one that was being instantiated. I didn't realize that both contexts were being instantiated but the 2nd one was what was actually being called, and since I hadn't created compiled views for it, it was taking a long time each time the test application would run. Now the initial query is 18 seconds instead of 15 minutes because I'm using the 2nd context with the newly compiled views.

现在,我有2个上下文项目(MyCompany.Context,MyCompany.SystemContext)和MyCompany.DomainClasses项目,MyCompany.Model项目以及MyCompany.DomainMappings项目.我使用T4脚本在两个上下文项目中生成视图,并且使用复制的链接将MyCompany.DomainClasses中的视图文件包括在内,以便在重新生成时也更新域类文件.这样,实体框架就可以检测已编译的视图,从而减少了第一次查询的启动时间.

Now, I have 2 context projects (MyCompany.Context, MyCompany.SystemContext) and a MyCompany.DomainClasses project, MyCompany.Model project and a MyCompany.DomainMappings project. I use the T4 script to generate the views in both context projects and I included the view files from the MyCompany.DomainClasses using a copied link so that when it regenerates, it also updates the Domain Classes file. This allows the Entity Framework to detect the compiled views which reduces the startup time for the 1st query.

这篇关于当上下文位于与域类不同的项目中时,应首先在哪个程序集中放置实体框架代码的已编译视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆