首页 > 解决方案 > 如何在 ABP 框架中创建自定义 ID?

问题描述

在 ABP 框架中,我们有一个具有 Id 的实体,但是如果我的表有一个名为 ProductId 的 Id,那么如何将 ProductId 与来自实体的 Id 相关联?

标签: c#abp

解决方案


您可以尝试使用您想要的名称创建一个 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

它应该可以工作


推荐阅读