Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

[PROBLEM] Entity with Unique Index attribute + SoftDelete #1755


User avatar
0
feliw created

Hi,

Currently in the project that I working on, we have an entity that need to implement Unique Index attribute and that entity also is ISoftDelete entity. So even if the record is deleted it still cannot insert the entity with same "Code " value. Does it mean that I cannot use this ISoftDelete and Unique Index attribute together ?

Thanks before :D


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

    Hi,

    I think Sql Server does not allow that. You can include IsDeleted column to your unique index.

  • User Avatar
    0
    feliw created

    Okay understand your suggestion. Thanks man !! :D

  • User Avatar
    0
    manojreddy created

    If let's say I have a deleted a row, again create a row with same unique index attribute. Now If I again delete the record it will give an error. So How can We solve this issue?

  • User Avatar
    0
    aaron created
    Support Team

    Add a column:

    public Guid DeletionToken { get; set;
    } = Guid.Empty;
    

    Include it in unique index attribute. Set this with Guid.NewGuid() when deleting.