foreign-keys - 在另一个表中将 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 那么它工作正常。
需要帮助来正确设置用户外键。
解决方案
推荐阅读
- reporting-services - SSRS 报表的查询设计器屏幕只有两个工具(编辑为文本和导入)
- ruby-on-rails - InstanceDouble(会话)(匿名)>收到意外消息:[]= with
- java - Java FileChannel.size() vs File.length() - 在 FileChannel.truncate() 之后
- c++ - 使用模板时出现错误:编译器错误 C2770:“模板”的显式模板或通用参数无效
- php - 可以从谷歌检查器工具复制粘贴和覆盖吗
- rust - 通过方法获取值而不移动它的正确方法是什么?
- python - 传递给 C DLL 函数时如何从 Python 结构中删除填充
- android - 基于按钮单击更改 Recyclerview 的 Firebase 数据库
- c++ - 如何完整读取 INI 文件?
- monaco-editor - 使用 Monaco 编辑器的自定义模式自动建议 JSON 文件?