I'm trying to use the EntityFramework.BulkInsert
extension but I keep getting an exception of Type 'MyEntity.CallDetail' is not found in context 'MyEntity.MyEntities'
. I tracked this exception to the DBMapping
class in the EntityFramework.MappingAPI
. The method that throws it is :
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 the EntityFramework.MappingAPI
or this this 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'm assuming that the error is caused by everything being DBSet<...>
instead of just the type but I may be wrong.
If it is in my code (which is most probable) what do I need to do to make this work?
EDIT: Thanks to @BenRobinson, the issue is due to the EF mapping. I have been able to find that others have been having similar issues with EntityFramework.MappingAPI
on DB first models as found here, here, and here. Since I am new to EF, I'm hoping that someone can see an issue in the edmx
that could be causing the problem. Below is the info 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>
<!-- C-S mapping content -->
<edmx:Mappings>
<Mapping Space="C-S" 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>
I was having this same issue, and was able to resolve it simply by updating my EntityFramework.MappingAPI ! NuGet MappingAPI . After updating, I simply rebuilt my project and no longer had the exception.
This exact error and proposed solution worked for me. After installation of the EntityFramework.BulkInsert-ef6 package, go back to Manage NuGet Packages and there should be an Update for EntityFramework.MappingAPI. After updating, run your context.BulkInsert(listOfObjects); line and it should succeed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With