I am writing a c# class as below. I have roll number of the student as a unique key in a table is there any way I can lock based on rollNo, if modification from multiple threads with the same roll number is not allowed and with different roll number it should be allowed.
Class ABC
{
public Void UpdateStudent(int rollNo)
{
student = fetchRecord();
if(some condtion)
{
//Update Student table
}
if(some condtion)
{
//Update Student table
}
if(some condtion)
{
//Update Student table
}
// enter code here
}
}