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"> <edmx:Runtime> <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> <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> <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>
source share