找不到概念模型类型

发布于 2024-12-28 07:23:18 字数 1127 浏览 1 评论 0原文

我在 MVC3 项目 A 和 B 中有两个实体数据模型。

我最近添加了新的实体数据模型 B 来处理一些新功能,问题是现在现有代码已停止工作,当我遇到以下错误时尝试访问实体模型 A 中的代码。

错误消息是:

找不到概念模型类型“project.models.Bclass”

我不明白为什么这个新功能会影响当前的代码,因为实体模型 A 没有以任何方式改变。功能 B 位于单独的类中,不会干扰模型 A。

当从项目中删除新代码并且排除实体模型 B 时,代码将按其应有的方式工作。

以下是错误的一些堆栈跟踪:

Exception : Could not find the conceptual model type for 'Project1.Models.CrossSession'.
Application Class - method : System.Data.Metadata.Edm.MetadataWorkspace -- GetEdmSpaceType
User : temp.user
Url : http://localhost/project1/auth/message
Stacktrace :    at System.Data.Metadata.Edm.MetadataWorkspace.GetEdmSpaceType(StructuralType objectSpaceType)
   at System.Data.Entity.Internal.InternalContext.UpdateEntitySetMappings()
   at System.Data.Entity.Internal.InternalContext.TryUpdateEntitySetMappingsForType(Type entityType)
   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
   at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()

I have two Entity Data models within a MVC3 project A and B.

I have recently added the new entity data model B to deal with some new functionality, the issue is that now the existing code has stopped working and I am getting the following error when trying to access code within entity model A.

The error message is:

Could not find the conceptual model type 'project.models.Bclass'

I do not understand why it is this new functionality has affected the current code seeing as entity model A has not change in any way. And functionality B is in a separate class and does not interfere with model A.

When the new code is removed from the project and entity model B is excluded then the code works as it should.

Here is some of the stacktrace from the error:

Exception : Could not find the conceptual model type for 'Project1.Models.CrossSession'.
Application Class - method : System.Data.Metadata.Edm.MetadataWorkspace -- GetEdmSpaceType
User : temp.user
Url : http://localhost/project1/auth/message
Stacktrace :    at System.Data.Metadata.Edm.MetadataWorkspace.GetEdmSpaceType(StructuralType objectSpaceType)
   at System.Data.Entity.Internal.InternalContext.UpdateEntitySetMappings()
   at System.Data.Entity.Internal.InternalContext.TryUpdateEntitySetMappingsForType(Type entityType)
   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
   at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

凉宸 2025-01-04 07:23:18

找到解决方案。在某些情况下(随机),实体框架生成的代码中出现了混淆。这显然是一个已知的错误,并且应该在未来的版本中进行修复。同时,解决此问题的方法是将 efm 移至解决方案中的单独类。

Solution found. It appears in some cases (randomly) there is a mix up in the code generated by the entity framework. This is apparently a known bug and a fix should be coming in future releases. In the mean time the way around this is to move the efm to a separate class within the solution.

简美 2025-01-04 07:23:18

一个可能的解释是,如果您使用数据库优先方法并忘记添加实体类,您将收到此错误。

即(来自下面链接的指南)

  1. 右键单击模型的设计器表面。
  2. 从上下文菜单中,选择添加代码生成项。
  3. 在打开的“添加新项目”对话框中,从左侧已安装的模板类型列表中选择“数据”。
  4. 选择 ADO.NET DbContext Generator,然后单击添加
    按钮。

我通常使用 Julie Lerman 的指南; https://msdn.microsoft.com/en -us/library/jj206878(v=vs.113).aspx

One possible explanation is that if you use the database first approach and forget to add the Entity classes, you will get this error.

i.e. (from the guide linked below)

  1. Right click on the model’s designer surface.
  2. From the context menu, choose Add Code Generation Item.
  3. In the Add New Item dialog that opens, select Data from the list of installed templates types on the left.
  4. Choose the ADO.NET DbContext Generator then click the Add
    button.

I normally use Julie Lerman's guide; https://msdn.microsoft.com/en-us/library/jj206878(v=vs.113).aspx

没有心的人 2025-01-04 07:23:18

通过将 EntityFramework 更新到最新版本(6.0)解决了这个问题
http://nuget.org/packages/EntityFramework/

安装后重新生成模型即可工作;)

Solved this by updating EntityFramework to the latest version (6.0)
http://nuget.org/packages/EntityFramework/.

After installing it regenerate the models and it will work ;)

世界如花海般美丽 2025-01-04 07:23:18

我在同一项目中的 2 个不同的 .edmx 文件中遇到了同样的问题。
对于第一个 .edmx 模型,我使用了“添加代码生成项”,对于第二个模型,我没有使用。该项目正在正确构建,但在运行时抛出该异常。

我还解决了为第二个 .edmx 模型生成 .tt 类的问题。

I had the same problem with 2 different .edmx files in the same project.
For the first .edmx model I had used "Add Code Generation Item", for the second model I hadn't. The project was building correctly but throwing that exception on runtime.

I solved generating the .tt classes for the second .edmx model as well.

南巷近海 2025-01-04 07:23:18

好吧,我刚刚安装了 EF 4.1 并尝试将 DbContext 与 EMDX 结合起来 - 当我尝试传回视图时,我得到了同样的错误 - 这就是我最终来到这里的原因......我认为解决这个问题的方法是将功能分离出来分成解决方案中的单独组件...

Well I just installed EF 4.1 and tried to combine DbContext with a EMDX - When I tried to pass back a view I got the same error - that's why I ended up here... I think the way around this is to separate the functionality out into separate asemblies in the solution...

策马西风 2025-01-04 07:23:18

这也可以通过在 Visual Studio 2010 中生成新的 edmx 来解决,以便它与旧的相匹配......(并复制它生成的文件)

This can also be resolved by generating the new edmx in visual studio 2010 so it matches the older ones... (And copying over the files it generates)

厌味 2025-01-04 07:23:18

我正在使用一些旧版软件,并不热衷于升级 EF。对于我来说,需要更改新添加的 .edmx 的以下设置,以匹配项目中已存在的 .edmx。我的新名称为“T4”,我将其更改为“旧对象上下文”。我确实必须删除之前生成的 .tt 模板才能构建它。否则,旧生成的文件将保留在那里,新文件也将保留在那里,从而导致“属性已定义”错误。感谢上面所有帮助我解决这个问题的答案!

(属性面板,单击实体设计器后)
代码生成房地产策略

I was working with some legacy software and was not keen on upgrading EF. For me, the below setting on my newly added .edmx needed to be changed to match the .edmx that already existed in the project. My new one said "T4" and I changed it to "Legacy Object Context". I did have to delete the .tt templates that were generated previously in order to get it to build. Otherwise, the old generated files stay there and the new files are also there, causing "property already defined" errors. Thx to all the answers above that helped me figure this out!

(Properties panel, after clicking in the entity designer)
Code Generation Strategy in Properties

懵少女 2025-01-04 07:23:18

使用Visual Studio 12,问题仍然没有解决。作为替代解决方法,我使用早于实体模型的“老式”数据类设置了第二个 SQL 数据模型 - 它们仍然存在并且仍然有效。使用添加 - 新项目 - (数据类别) - LINQ To SQL 类,打开 ServerExplorer,找到服务器和数据库,然后将其拖放到数据类窗格中。老派 - 但当不需要实体模型的全部功能时,可以轻松地克服这个非常不方便的问题。

Using Visual Studio 12, the issue has still not been resolved. As an alternative workaround, I set up the second SQL data model using "old fashioned" Data Classes that pre-date entity models - they're still there and they still work. Use Add - New Item - (Data Category) - LINQ To SQL Classes, open the ServerExplorer, locate the server and database, then drag and drop it onto the data classes pane. Old school - but conveniently overcomes this highly inconvenient issue when the full functionality of entity models is not needed.

仙气飘飘 2025-01-04 07:23:18

我删除了 edmx 模型,删除了实体包,重新安装实体 5.0 并工作。

I removed the edmx models, removed the Entity package, re-install the entity 5.0 and works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文