首页 新闻 会员 周边

C# EF TPC

0
悬赏园豆:100 [已解决问题] 解决于 2019-04-08 12:37

System.NotSupportedException: All objects in the EntitySet 'AbpZeroTemplateDbContext.BasicInfoes' must have unique primary keys. However, an instance of type 'Bit.Cis.Mg58Infos.Estate' and an instance of type 'Bit.Cis.Mg58Infos.RentHouse' both have the same primary key value, 'EntitySet=BasicInfoes;Id=1'.

我的类 Estate 和 RentHouse 同时继承了BasicInfoes。

问题补充:

public partial class RentHouse : BasicInfo,ISoftDelete
{
#region Properties
///<summary>
/// 面积
///</summary>
public virtual double? Size { get; set; } // Size
public bool IsDeleted { get ; set ; }
#endregion Properties
}

public partial class Estate : BasicInfo
{

    #region Properties 
    ///<summary>
    /// 面积
    ///</summary>
    public virtual double? Size { get; set; } // Size

    #endregion Properties      
}


public partial class BasicInfo : CreationAuditedEntity<long>
{

    #region Properties 

    ///<summary>
    /// 区域
    ///</summary>
    ///<remarks>
    /// 为空表示全美国
    ///</remarks>
    public virtual string AreaId { get; set; } // AreaId (length: 50)

    ///<summary>
    /// 区号
    ///</summary>
    ///<remarks>
    /// 为空表示区域
    ///</remarks>
    public virtual string AreaCode { get; set; } // AreaCode (length: 10)

    ///<summary>
    /// 类别
    ///</summary>
    public virtual string CategoryId { get; set; } // CategoryId (length: 50)



    ///<summary>
    /// 消息类型
    ///</summary>
    ///<remarks>
    /// 由系统自动赋值,如:Estate、Transfer
    ///</remarks>
    public virtual string MsgType { get; set; } // MsgType (length: 50)

    #endregion Properties      
    
}

ERROR 2019-04-02 16:00:21,347 [72 ] nHandling.AbpApiExceptionFilterAttribute - All objects in the EntitySet 'AbpZeroTemplateDbContext.BasicInfoes' must have unique primary keys. However, an instance of type 'Bit.Cis.Mg58Infos.Estate' and an instance of type 'Bit.Cis.Mg58Infos.RentHouse' both have the same primary key value, 'EntitySet=BasicInfoes;Id=1'.
System.NotSupportedException: All objects in the EntitySet 'AbpZeroTemplateDbContext.BasicInfoes' must have unique primary keys. However, an instance of type 'Bit.Cis.Mg58Infos.Estate' and an instance of type 'Bit.Cis.Mg58Infos.RentHouse' both have the same primary key value, 'EntitySet=BasicInfoes;Id=1'.
在 System.Data.Entity.Core.Common.Internal.Materialization.Shaper.UpdateEntryTEntity
在 System.Data.Entity.Core.Common.Internal.Materialization.Shaper.HandleEntityTEntity
在 lambda_method(Closure , Shaper )
在 System.Data.Entity.Core.Common.Internal.Materialization.Coordinator1.ReadNextElement(Shaper shaper) 在 System.Data.Entity.Core.Common.Internal.Materialization.Shaper1.SimpleEnumerator.MoveNext()
在 System.Data.Entity.Core.Objects.ObjectContext.ProcessRefreshedEntities(Dictionary2 trackedEntities, ObjectResult1 results)
在 System.Data.Entity.Core.Objects.ObjectContext.BatchRefreshEntitiesByKey(RefreshMode refreshMode, Dictionary2 trackedEntities, EntitySet targetSet, List1 targetKeys, Int32 startFrom)
在 System.Data.Entity.Core.Objects.ObjectContext.RefreshEntities(RefreshMode refreshMode, IEnumerable collection)
在 System.Data.Entity.Core.Objects.ObjectContext.Refresh(RefreshMode refreshMode, Object entity)
在 System.Data.Entity.Internal.InternalEntityEntry.Reload()
在 Abp.EntityFramework.AbpDbContext.CancelDeletionForSoftDelete(DbEntityEntry entry)
在 Abp.EntityFramework.AbpDbContext.ApplyAbpConcepts()
在 Abp.EntityFramework.AbpDbContext.<SaveChangesAsync>d__46.MoveNext()

周兴兴的主页 周兴兴 | 初学一级 | 园豆:116
提问于:2019-04-02 16:17
< >
分享
最佳答案
0

跟踪的实体对象的主键值重复,就是说有两个对象的主键值是一样的。

收获园豆:100
通信的搞程序 | 小虾三级 |园豆:1747 | 2019-04-02 22:22

是您这个意思,但不是解决这个问题的答案。因为我使用的是 EF TPT ,是继承的方式实现。按理说没长表的数据是独立。不应该存在实体对象的主键值重复的现象。这才是我想找这个问题的原因。我也访问了google ,上面也有人提了这个问题,这个问题也没解决。我认为可能是 EF TPT 的坑,就是不知道怎么跳过。准备环 .NET Core 版的来实现。

周兴兴 | 园豆:116 (初学一级) | 2019-04-03 00:13

谢谢朋友!这里有一篇文章关于 EF中的TPH、TPT、TPC 的文章,朋友有时间的话,可以去看看 TPT 的方式,我算是被TPT 坑了。https://www.cnblogs.com/suizhikuo/p/3840150.html

周兴兴 | 园豆:116 (初学一级) | 2019-04-03 00:18
其他回答(1)
0

这个问题,就算了吧。我还没解决。我换了种方式去实现我要的功能了。过

周兴兴 | 园豆:116 (初学一级) | 2019-04-08 12:33
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册