I'm new to EF. Let's say I have a table in DB like this:
ID FirstName LastName DateOfBirth ------------------------------------------- 1 John Smith 1.1.1990 2 Mary Wilson 5.1.1991 Now I insert new entity into the table using EF:
dbcontext.Persons.Add(new Person { FirstName = "John", LastName = "Smith", DateOfBith = "1.1.1990" }); dbcontext.SaveChanges(); I need the code to throw an exception because this row already exists in the database but what EF does is that it increments the ID column by 1 and creates new record:
ID FirstName LastName DateOfBirth -------------------------------------------- 1 John Smith 1.1.1990 2 Mary Wilson 5.1.1991 3 John Smith 1.1.1990 Is EF even capable of doing this?
Personin C# ?