C# 在上下文中找不到类型,可能存在映射问题

C# 在上下文中找不到类型,可能存在映射问题,c#,entity-framework-6,C#,Entity Framework 6,我正在尝试使用EntityFramework.BulkInsert扩展,但在上下文“MyEntity.MyEntities”中找不到类型为“MyEntity.CallDetail”的异常。我将此异常跟踪到EntityFramework.MappingAPI中的DBMapping类。抛出它的方法是: public IEntityMap this[string typeFullName] { get { if (!_tableM

我正在尝试使用
EntityFramework.BulkInsert
扩展,但在上下文“MyEntity.MyEntities”中找不到类型为“MyEntity.CallDetail”的
异常。我将此异常跟踪到
EntityFramework.MappingAPI
中的
DBMapping
类。抛出它的方法是:

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

            return _tableMappings[typeFullName];
        }
    }
我的问题是,这是EntityFramework.MappingAPI中的错误还是我的代码中的某个错误

我的上下文类:

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; }
}

我遇到了同样的问题,只需更新EntityFramework.MappingAPI!就可以解决它。更新后,我只是重新构建了我的项目,不再有例外。

这个确切的错误和建议的解决方案对我有效。安装EntityFramework.BulkInsert-ef6包后,返回管理NuGet包,EntityFramework.MappingAPI应该会有更新。更新后,运行context.BulkInsert(ListofObject);行,它应该会成功。

EntityFramework.MappingAPI和EntityFramework.BulkInsert-EFx未被禁用。应使用Z.EntityFramework.Extensions包


语法现在有点不同了(例如,
db.BulkInsert(addresses,bulk=>bulk.InsertKeepIdentity=true);
),但它对我来说非常有用。

几乎可以肯定,您的代码是EF。您还没有显示任何映射代码,如何映射您的实体?Fluent api还是attributes?@BenRobinson说到EF,我是比较新的,我没有改变EF向导生成的任何映射。除了向导所做的工作之外,我还需要映射表吗?您是先使用代码还是先使用数据库来映射edmx文件?先使用数据库来映射生成的edmx@BenRobinson我添加了生成的edmxThank you的相对部分,这对我很有用,在其他地方找不到这个答案。是的,看起来BulkInsert需要更新版本的MappingAPI
<?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>