Type not found in context, possible display problem

I am trying to use the EntityFramework.BulkInsert extension, but I get a Type 'MyEntity.CallDetail' is not found in context 'MyEntity.MyEntities' exception Type 'MyEntity.CallDetail' is not found in context 'MyEntity.MyEntities' . I tracked this exception in the DBMapping class in EntityFramework.MappingAPI . The method that throws it:

  public IEntityMap this[string typeFullName] { get { if (!_tableMappings.ContainsKey(typeFullName)) throw new Exception("Type '" + typeFullName + "' is not found in context '" + _contextTypeName + "'"); return _tableMappings[typeFullName]; } } 

My question is: is this an error in EntityFramework.MappingAPI or is it something in my code?

My context class:

 public partial class MyEntities : DbContext { public MyEntities() : base("name=MyEntities") { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { throw new UnintentionalCodeFirstException(); } public virtual DbSet<CallDetail> CallDetail { get; set; } public virtual DbSet<PhoneState> PhoneStates { get; set; } public virtual DbSet<Skill> Skills { get; set; } public virtual DbSet<Team> Teams { get; set; } public virtual DbSet<User> Users { get; set; } public virtual DbSet<StateLog> StateLogs { get; set; } } 

I assume that the error is caused by the fact that everything is DBSet<...> , not just a type, but I could be wrong.

If this is in my code (which is most likely), what do I need to do to make this work?

EDIT: Thanks to @BenRobinson, the problem is with EF mapping. I managed to find that others had problems with EntityFramework.MappingAPI on the first DB models, as found here , here , and here . Since I am new to EF, I hope someone can see the problem in edmx , which may cause the problem. The following is information from the edmx file:

 <?xml version="1.0" encoding="utf-8"?> <edmx:Edmx Version="3.0" xmlns:edmx="http://schemas.microsoft.com/ado/2009/11/edmx"> <!-- EF Runtime content --> <edmx:Runtime> <!-- SSDL content --> <edmx:StorageModels> <Schema Namespace="my_contactModel.Store" Provider="MySql.Data.MySqlClient" ProviderManifestToken="5.6" Alias="Self" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl"> <EntityType Name="call_detail"> .... </EntityType> <EntityContainer Name="my_contactModelStoreContainer"> <EntitySet Name="call_detail" EntityType="Self.call_detail" Schema="my_contact" store:Type="Tables" /> .... </EntityContainer> </Schema></edmx:StorageModels> <!-- CSDL content --> <edmx:ConceptualModels> <Schema Namespace="MyContactModel" Alias="Self" annotation:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm"> <EntityType Name="CallDetail"> .... </EntityType> <EntityContainer Name="MyEntities" annotation:LazyLoadingEnabled="true"> <EntitySet Name="CallDetail" EntityType="MyContactModel.CallDetail" /> .... </EntityContainer> </Schema> </edmx:ConceptualModels> <!-- CS mapping content --> <edmx:Mappings> <Mapping Space="CS" xmlns="http://schemas.microsoft.com/ado/2009/11/mapping/cs"> <EntityContainerMapping StorageEntityContainer="my_contactModelStoreContainer" CdmEntityContainer="MyEntities"> <EntitySetMapping Name="CallDetail"> <EntityTypeMapping TypeName="MyContactModel.CallDetail"> <MappingFragment StoreEntitySet="call_detail"> .... </MappingFragment> </EntityTypeMapping> </EntitySetMapping> </EntityContainerMapping> </Mapping> </edmx:Mappings> </edmx:Runtime> </edmx:Edmx> 
+6
source share
3 answers

I had the same problem and I was able to solve it simply by updating my EntityFramework.MappingAPI! NuGet MappingAPI . After the upgrade, I just rebuilt my project and no longer had an exception.

+11
source

This exact error and the proposed solution worked for me. After installing the EntityFramework.BulkInsert-ef6 package, return to "NuGet Package Management" and there should be an update for EntityFramework.MappingAPI. After the update, run your .BulkInsert context (listOfObjects); and he must succeed.

+6
source

EntityFramework.MappingAPI and EntityFramework.BulkInsert-EFx are not salted. You must use the Z.EntityFramework.Extensions package.

https://www.nuget.org/packages/Z.entityframework.extensions

The syntax is a bit different right now (e.g. db.BulkInsert(addresses, bulk => bulk.InsertKeepIdentity = true); ), but it works fine for me.

+1
source

Source: https://habr.com/ru/post/975309/


All Articles