实体框架错误“实体类型未映射。”

发布于 2024-11-02 18:03:29 字数 1544 浏览 1 评论 0原文

我们在项目中使用实体框架,并且我在模型中构建了一个实体。然后我有一个使用存储过程的函数导入。函数导入创建的方法应该返回我创建的自定义实体的集合。

问题是我在构建时收到错误,提示“实体类型‘someentity’未映射。

这是什么意思?它是否因为该实体没有底层数据存储而感到不安?它不需要一个,函数导入返回该实体的实例,我不需要更新、编辑或插入这种类型的实体。

函数导入工作得很好,并根据需要返回我的实体的集合,但这个错误很烦人。将其列为编译错误,它实际上并不会阻止解决方案的编译

更新

如果我在 XML 编辑器中打开 EDMX 并双击错误列表中的错误,它会以红色突出显示此 XML 块:

   <EntityContainerMapping StorageEntityContainer="KlasEntitiesStoreContainer" CdmEntityContainer="KlasEntities">
      <EntitySetMapping Name="VendorBriefs"><EntityTypeMapping TypeName="KlasEntityDataModel.VendorBrief"><MappingFragment StoreEntitySet="ev_VendorBriefs">
        <ScalarProperty Name="VendorBriefID" ColumnName="VendorBriefID" />
        <ScalarProperty Name="Title" ColumnName="Title" />
        <ScalarProperty Name="Link" ColumnName="Link" />
        <ScalarProperty Name="LinkText" ColumnName="LinkText" />
        <ScalarProperty Name="BriefPath" ColumnName="BriefPath" />
        <ScalarProperty Name="Description" ColumnName="Description" />
        <ScalarProperty Name="IsActive" ColumnName="IsActive" />
        <ScalarProperty Name="DisplayOrder" ColumnName="DisplayOrder" />
      </MappingFragment></EntityTypeMapping></EntitySetMapping>
      <FunctionImportMapping FunctionImportName="SearchForVendorProductByKlasID" FunctionName="KlasEntities.Store.ev_ds_Products_SearchByKLASID" />
    </EntityContainerMapping>

We are using Entity Framework in our project and I have an entity that I built in my model. I then have a function import that uses a stored procedure. The method created by the function import is supposed to return a collection of the custom entity I created.

The problem is that I get an error when I build that says "The entity type 'someentity' is not mapped.

What does this mean? Is it upset because the entity does not have an underlying data store? It doesn't need one, the function import returns instances of this entity and I have no need to update, edit, or insert entities of this type.

The function import works great and returns a collection of my entity as desired, but this error is annoying. Though the error list lists it as a compile error, it does not actually stop the solution from compiling.

Update

If I open the EDMX in the XML editor and double click the error in the error list it highlights this chunk of XML in red:

   <EntityContainerMapping StorageEntityContainer="KlasEntitiesStoreContainer" CdmEntityContainer="KlasEntities">
      <EntitySetMapping Name="VendorBriefs"><EntityTypeMapping TypeName="KlasEntityDataModel.VendorBrief"><MappingFragment StoreEntitySet="ev_VendorBriefs">
        <ScalarProperty Name="VendorBriefID" ColumnName="VendorBriefID" />
        <ScalarProperty Name="Title" ColumnName="Title" />
        <ScalarProperty Name="Link" ColumnName="Link" />
        <ScalarProperty Name="LinkText" ColumnName="LinkText" />
        <ScalarProperty Name="BriefPath" ColumnName="BriefPath" />
        <ScalarProperty Name="Description" ColumnName="Description" />
        <ScalarProperty Name="IsActive" ColumnName="IsActive" />
        <ScalarProperty Name="DisplayOrder" ColumnName="DisplayOrder" />
      </MappingFragment></EntityTypeMapping></EntitySetMapping>
      <FunctionImportMapping FunctionImportName="SearchForVendorProductByKlasID" FunctionName="KlasEntities.Store.ev_ds_Products_SearchByKLASID" />
    </EntityContainerMapping>

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

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

发布评论

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

评论(5

单身情人 2024-11-09 18:03:29

每个实体必须映射到 QueryView 或数据库表/定义查询。您无法创建根本没有映射的实体。如果您想定义未映射到模型中的函数导入结果,则必须将 VendorBrief 定义为复杂类型。

Each entity must be mapped either to QueryView or to database table / defining query. You can't create the entity which is not mapped at all. If you want to define result of function import which is not mapped in your model you must define your VendorBrief as complex type.

独守阴晴ぅ圆缺 2024-11-09 18:03:29
  1. 打开数据模型(edmx 文件)
  2. 右键单击​​数据模型并选择模型浏览器
  3. 在模型浏览器窗口中转到函数导入并删除相应的项目。
  1. Open the datamodel (edmx file)
  2. Right-click in the datamodel and select Model Browser
  3. In the model browser window go to Function Imports and delete the appropriate items.
泪是无色的血 2024-11-09 18:03:29

尝试打开您的实体文件图 .edmx。然后使用DEL删除所有表。然后右键单击图表内部并选择从数据库更新模型。

Visual Studio 在这方面有点问题。

Try to open your Entity file diagram, the .edmx. And then delete all the tables using DEL. And then right click inside the diagram and select Update Model from Database.

The Visual Studio is a little bugged in this stuff.

把昨日还给我 2024-11-09 18:03:29

您是否尝试过使用复杂类型而不是实体来表示它并映射到它?

http://msdn.microsoft.com/en-us/library/bb738472.aspx

Have you tried representing it using a Complex Type instead of an Entity and mapping to that instead?

http://msdn.microsoft.com/en-us/library/bb738472.aspx

落在眉间の轻吻 2024-11-09 18:03:29

我也遇到了这个问题,但是当我在 XML 编辑器中打开 edmx 时,错误就消失了。我尝试了删除表然后更新 edmx 的所有变体。

我遇到的另一件奇怪的事情是,错误指的是两个表之间的关系,但是当我双击错误消息时,它突出显示了除它所指的两个表之外的另一个表。

I was having this issue as well but the error just went away when I opened the edmx in the XML editor. I tried all variations of removing tables then updating the edmx.

The other odd thing I was having, the error was referring to a relationship between two tables but when I double clicked on the error message it highlighted another table other than the two it was referring to.

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