Hi,@fatih uyanık. Welcome to Microsoft Q&A Forum.
The error you are encountering seems to be related to violating a unique constraint on the Id field in the Readers table. This error typically occurs when you are trying to insert a record with an Id value that already exists in the table. If you're attempting to add new records without closing the window, you might be reusing the same Id value inadvertently.
To fix this error, you need to ensure that each new record has a unique Id value when it is added to the database. You could try the following steps:
Check your database schema to ensure that the Id field is set to auto-increment or is generated automatically to guarantee uniqueness. Ensure that you are not explicitly setting the Id value when creating a new Readers object before saving it to the database. Let the database handle the generation of the Id automatically.
Double-check your application logic to ensure that you are not inadvertently using the same Id value for different records. If you are manually assigning Id values, make sure they are unique for each new record.
Here's an example of how to create a new Readers object without setting the Id explicitly:
using (var context = new YourDbContext())
{
var newReader = new Readers
{
// Set other properties here
// Id will be automatically generated by the database
};
context.Readers.Add(newReader);
context.SaveChanges();
}
If the problem persists, it may help to check your code and database settings.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.