rider-efcore icon indicating copy to clipboard operation
rider-efcore copied to clipboard

Third-party: EntityFramework.Exceptions: Known exceptions wrapping

Open seclerp opened this issue 2 years ago • 0 comments

When the project uses EntityFramework.Exceptions, SaveChanges/SaveChangesAsync could lead to exceptions. E.g.:

context.Posts.Insert(post);
context.{caret}SaveChanges(); // Warning EFXXXX: EF Core state mutatioon could lead to exceptions
context.Posts.Insert(post);

try
{
  context.SaveChanges();
}
catch (UniqueConstraintException ex)
{
  {selstart}throw new NotImplementedException();{selend}
}

The fix should generate exception-catching blocks according to an analysis of the model and context. For example, [UniqueConstraint] or [ForeignKey] attributes could lead to UniqueConstraintException and ReferenceConstraintException respectively.

Full list of currently available exceptions:

  • UniqueConstraintException
  • CannotInsertNullException
  • MaxLengthExceededException
  • NumericOverflowException
  • ReferenceConstraintException

seclerp avatar Jul 12 '22 14:07 seclerp