Base solution for your next web application
Open Closed

no id but other unique key #1699


User avatar
0
iamnish created

I have sslno as identity key and according to ur article i have implemented as below

public class Salemast : FullAuditedEntity, IMustHaveTenant {

[NotMapped]
public override int Id
{
    get { sslno; }
    set { /* nothing */ }
}

}

but u have given a note that------------ Only problem is that: you carefully use this entity since Id is meaningless. So, Repositories some methods (works with Id) will not be used. may i know what exactly will not work?


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    If you look at this class you will see that Id field is used hard coded in places which returns value of entity Id. <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/763e718341a42ef1799d9ded5fae228f652d7a6b/src/Abp.EntityFramework/EntityFramework/Repositories/EfRepositoryBaseOfTEntityAndTPrimaryKey.cs">https://github.com/aspnetboilerplate/as ... maryKey.cs</a>

    For example InsertAndGetId method.

    And the methods which you pass the value of Id will not work because of CreateEqualityExpressionForId method in this class. Because it uses Id property hard coded as well. <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/763e718341a42ef1799d9ded5fae228f652d7a6b/src/Abp/Domain/Repositories/AbpRepositoryBase.cs#L255">https://github.com/aspnetboilerplate/as ... se.cs#L255</a>

    Do you only need a different unique key name for a single entity ? If so, you can create a custom repository for this entity. <a class="postlink" href="http://aspnetboilerplate.com/Pages/Documents/Repositories#custom-repositories">http://aspnetboilerplate.com/Pages/Docu ... positories</a>

    If all or most of your entities have a different key than Id, then you can override base entity methods like Get, InsertAndReturnId etc...