c# - 如何在 ABP 框架中创建自定义 ID?
问题描述
在 ABP 框架中,我们有一个具有 Id 的实体,但是如果我的表有一个名为 ProductId 的 Id,那么如何将 ProductId 与来自实体的 Id 相关联?
解决方案
您可以尝试使用您想要的名称创建一个 id,但是在使用存储库时,您必须使用类型的存储库(在通用存储库中没有 id),
IRepository<Something>
https://docs.abp.io/en/abp/latest/AspNet-Boilerplate-Migration-Guide#injecting-the-repositories
要使用该存储库,您的实体必须实现 IEntity,并且您必须配置到数据库的映射,您的实体应该是这样的
public class Something: IEntity
{
public long SomeId {get; set; }
public object [] GetKeys ()
{
return new object [] {SomeId};
}
}
https://docs.abp.io/en/abp/latest/Best-Practices/Entity-Framework-Core-Integration#model-mapping
它应该可以工作
推荐阅读
- javascript - 通过 5 个单独的输入块过滤表
- c - “...”在 C 中作为函数参数有什么作用?
- java - 1/8 测试用例的简单 If/Else 问题失败
- javascript - 未定义的 handleSubmit 函数登录表单
- java - 如何为从 Spring Data JPA 存储库生成的所有 SQL 查询设置注释
- batch-file - 如何使用批处理文件中的环境变量更改为目录?
- node.js - 附加 Blob 未正确连接 pdf 页面
- python - Python中的二维直方图二维高斯函数拟合
- c++ - 阅读日期集合
- android - 是否有任何机制来检测请求是否来自系统级移动浏览器?