How to create a common utility method for handling avoid duplicate records insertion before inserted into sql server database in asp.net dynamic data scaffolding?
Asked
Active
Viewed 866 times
1 Answers
0
To avoid duplicate records you can create a unique index on a table for one or multiple fields.
It seems that you are using Entity Framework for this. The following applies to EF 6.1 and later.
If you need one column to be unique you can add the schema data annotation to the datamember in the model :
[Index(IsUnique = true)]
public string OneField {get; set;}
If you need more columns to be unique at the same time you need to add the name of the index and the order in the index to the datamembers involved :
[Index("IDX_MyUniqueIndexName", 1, IsUnique = true)]
public string FirstField { get; set; }
[Index("IDX_MyUniqueIndexName", 2, IsUnique = true)]
public string SecondField { get; set; }

masterw
- 116
- 4
-
I'm using EF 5.0. Are there any way to do in EF 5.0 with customizing the .net code to avoid duplicate records added in asp.net dynamic data scaffolding site application? – temUser Mar 06 '15 at 04:33