gpt4 book ai didi

c# - 在上下文中找不到类型,可能是映射问题

转载 作者:太空狗 更新时间:2023-10-29 19:55:49 25 4
gpt4 key购买 nike

我正在尝试使用 EntityFramework.BulkInsert扩展名,但我不断收到 Type 'MyEntity.CallDetail' is not found in context 'MyEntity.MyEntities' 的异常.我将此异常跟踪到 DBMapping EntityFramework.MappingAPI 中的类.抛出它的方法是:

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

我假设错误是由于一切都是 DBSet<...> 引起的而不仅仅是类型,但我可能是错的。

如果它在我的代码中(这是最有可能的),我需要做什么才能使它工作?

编辑:感谢@BenRobinson,问题是由 EF 映射引起的。我发现其他人也遇到过与 EntityFramework.MappingAPI 类似的问题在发现的 DB 优先模型上 here , here , 和 here .由于我是 EF 的新手,我希望有人能在 edmx 中看到问题这可能是导致问题的原因。以下是 edmx 文件中的信息:

<?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>

最佳答案

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

关于c# - 在上下文中找不到类型,可能是映射问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25853967/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com