简体   繁体   English

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

[英]Entity framework error "Entity type is not mapped."

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.函数 import 创建的方法应该返回我创建的自定义实体的集合。

The problem is that I get an error when I build that says "The entity type 'someentity' is not mapped.问题是我在构建时收到一个错误,提示“实体类型‘someentity’未映射。

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.它不需要一个,函数 import 返回这个实体的实例,我不需要更新、编辑或插入这种类型的实体。

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:如果我在 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>

Each entity must be mapped either to QueryView or to database table / defining query.每个实体必须映射到 QueryView 或数据库表/定义查询。 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.如果要定义未映射到模型中的函数导入的结果,则必须将VendorBrief定义为复杂类型。

  1. Open the datamodel (edmx file)打开数据模型(edmx 文件)
  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.在模型浏览器窗口中,转到功能导入并删除相应的项目。

Try to open your Entity file diagram, the .edmx.尝试打开您的实体文件图,.edmx。 And then delete all the tables using DEL.然后使用 DEL 删除所有表。 And then right click inside the diagram and select Update Model from Database.然后在图表内右键单击并选择从数据库更新模型。

The Visual Studio is a little bugged in this stuff. Visual Studio 在这方面有点问题。

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 http://msdn.microsoft.com/en-us/library/bb738472.aspx

I was having this issue as well but the error just went away when I opened the edmx in the XML editor.我也遇到了这个问题,但是当我在 XML 编辑器中打开 edmx 时错误就消失了。 I tried all variations of removing tables then updating the edmx.我尝试了删除表然后更新 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.我遇到的另一件奇怪的事情是,错误是指两个表之间的关系,但是当我双击错误消息时,它突出显示了另一个表,而不是它所指的两个表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM