We have a large number of tables for setup forms.
In each form, there is a need to fill in the
Code and the
The Code consists of a
Now, the thing is, every time a user creates new data or updates the data, there is a need to check whether the
Code conflicts with the others or not.
In LINQ, this code checking is inevitable:
string ExistingCode = "ITEM01"; int ExistingKey = 1; var recordWithConflictedCode = (from a in db.MyTable where a.Code == ExistingCode && a.Key != ExistingKey).ToList(); if(recordWithConflictedCode.Count >= 1) return BadRequest("Duplicated Code found");
Now, since this involves a string comparison on every process, I think it makes sense to index the column
Code to make the query faster.
Is this a common practice for you guys?