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)
-
0
Hi,
I think Sql Server does not allow that. You can include IsDeleted column to your unique index.
-
0
Okay understand your suggestion. Thanks man !! :D
-
0
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?
-
0
Add a column:
public Guid DeletionToken { get; set; } = Guid.Empty;
Include it in unique index attribute. Set this with Guid.NewGuid() when deleting.