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

时间:2022-10-22 11:20:02

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.

我们在项目中使用Entity Framework,我有一个我在模型中构建的实体。然后我有一个使用存储过程的函数导入。函数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.

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

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.

函数import很好用,并根据需要返回我的实体的集合,但是这个错误很烦人。虽然错误列表将其列为编译错误,但它实际上并不会停止编译解决方案。

Any help is appreciated.

任何帮助表示赞赏。

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>

4 个解决方案

#1


10  

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.

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

#2


8  

  1. Open the datamodel (edmx file)
  2. 打开datamodel(edmx文件)
  3. Right-click in the datamodel and select Model Browser
  4. 在数据模型中单击鼠标右键,然后选择“模型浏览器”
  5. In the model browser window go to Function Imports and delete the appropriate items.
  6. 在模型浏览器窗口中,转到“功能导入”并删除相应的项目。

#3


6  

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.

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

The Visual Studio is a little bugged in this stuff.

Visual Studio在这个方面有点瑕疵。

#4


3  

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

#1


10  

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.

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

#2


8  

  1. Open the datamodel (edmx file)
  2. 打开datamodel(edmx文件)
  3. Right-click in the datamodel and select Model Browser
  4. 在数据模型中单击鼠标右键,然后选择“模型浏览器”
  5. In the model browser window go to Function Imports and delete the appropriate items.
  6. 在模型浏览器窗口中,转到“功能导入”并删除相应的项目。

#3


6  

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.

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

The Visual Studio is a little bugged in this stuff.

Visual Studio在这个方面有点瑕疵。

#4


3  

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