实体框架错误“实体类型未映射。”
我们在项目中使用实体框架,并且我在模型中构建了一个实体。然后我有一个使用存储过程的函数导入。函数导入创建的方法应该返回我创建的自定义实体的集合。
问题是我在构建时收到错误,提示“实体类型‘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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
每个实体必须映射到 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.尝试打开您的实体文件图 .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.
您是否尝试过使用复杂类型而不是实体来表示它并映射到它?
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
我也遇到了这个问题,但是当我在 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.