EntityFramework.Exceptions를 이용하면 EF Core에서 발생하는 데이터베이스 오류를 좀 더 쉽게 처리할 수 있습니다.
using (var demoContext = new DemoContext())
{
demoContext.Products.Add(new Product
{
Name = "a",
Price = 1
});
demoContext.Products.Add(new Product
{
Name = "a",
Price = 1
});
try
{
demoContext.SaveChanges();
}
catch (UniqueConstraintException e)
{
//Handle exception here
}
}