How to identify the Entity that throws the error when saving?

3

In my application, with Entity Framework, I make a query in an Entity Framework:

var lista = contexto.Rodada.Where(condições);

Then iterate over this list with a foreach.

During the iteration there are "updates" and "inserts" of several entities and one of them is responsible for the following error:

The conversion of a datetime2 data type to a datetime result in an out-of-range value. The statement has been terminated.

Searching, I saw that the reason for this error is that the default value (or minimum) for the datetime in C # is outside the accepted range of values in Sql Server:

vide link

I am trying to find where this occurs, but there are many datetimes across multiple entities, and the stack trace did not help me at all. Is there any way to identify the entity that has thrown the error?

    
asked by anonymous 17.03.2017 / 22:21

1 answer

1

Yes. I already answered this in another question that is not exactly a duplicate .

After implementation, place a breakpoint within the catch . Since there are many entities, the error is likely to be repeated by all entities of the same type.

Do not forget to also implement for SaveChangesAsync if you are using asynchronous methods to save.

    
17.03.2017 / 22:28