首页 > 解决方案 > 在另一个表中将 AbpUsers 设置为外键的问题

问题描述

我们在项目中使用 ABP.io。我们需要将 UserId 映射为我的新表中的外键。

我将外键映射到新表

public class NewEntity : FullAuditedEntity<int>, IHasIsActive
{
    ....    
    [ForeignKey("UserId")]
    public IdentityUser AppUser { get; set; }
}

它成功地创建了与 AbpUsers 表的外键关系。

现在,我试图在 NewEntity 表中插入记录,但它抛出错误

实体类型“IdentityUserLogin”需要定义一个主键。如果您打算使用无密钥实体类型,请调用“HasNoKey()”。

我们在代码中使用了 CrudAppService。

 public class NewEntityAppService :
        CrudAppService<NewEntity, NewEntityDto, int, PagedAndSortedResultRequestDto,
                       CreateUpdatePropertyTypeDto, CreateUpdatePropertyTypeDto>,
        IPropertyTypeAppService
    {
        private readonly IRepository<NewEntity, int> _newType;
        public PropertyTypeAppService(IRepository<NewEntity, int> newType)
            : base(newType)
        {
            _newType= newType;
        }

    }

对 AppUser 表的错误引用,因为 IdentityUser 类具有IdentityUserLogin。如果我评论 ForeignKey 那么它工作正常。

需要帮助来正确设置用户外键。

标签: foreign-keysabp

解决方案


推荐阅读