简体   繁体   中英

Entity Framework Core bug? SaveChanges throw select

I'm working with Entity Framework Core and .NET 5 and I detect some memory increased flows in server. When I see the console log, I see the problem, when a SaveChanges call fails, it throws a select of all tables and all records :(

My database is huge and full the memory. I've been searching the internet but couldn't find any similar error.

I hope someone has a solution. Thanks

The logs:

[10:59:45 WRN] Compiling a query which loads related collections for more than one collection navigation either via 'Include' or through projection but no 'QuerySplittingBehavior' has been configured. By default Entity Framework will use 'QuerySplittingBehavior.SingleQuery' which can potentially result in slow query performance. See https://go.microsoft.com/fwlink/?linkid=2134277 for more information. To identify the query that's triggering this warning call 'ConfigureWarnings(w => w.Throw(RelationalEventId.MultipleCollectionIncludeWarning))'

[10:59:46 DBG] Generated query execution expression: 'queryContext => new SingleQueryingEnumerable( (RelationalQueryContext)queryContext, RelationalCommandCache.SelectExpression(
Projection Mapping:
SELECT t.Id, t.AceptaTerminosYCondiciones, t.Activo, t.ContactoPrincipalId, t.CreatedBy, t.CurrentTimestamp, t.DateCreated, t.DateEdited, t.EditedBy, t.EstadoId, t.PersonaHumanaId, t.PersonaJuridicaId, t.TipoPersonaId, t.TipoSujetoObligadoId, t.UsuarioId, p.Id, p.CreatedBy, p.Cuit, p.CurrentTimestamp, p.DateCreated, p.DateEdited, p.EditedBy, p.FechaConstitucion, p.Jurisdiccion, p.NroInscripcion, p.RazonSocial, ....

In my case, I traced it down to Sherilog's ExceptionDetails sink.

Serilog.Exceptions is serializing DbUpdateException, which can result in an attempt to traverse the entire graph of objects associated with the exception. If you remove .Enrich.WithExceptionDetails() from the Serilog config,then things work as expected.

Please see the details here https://github.com/dotnet/efcore/issues/15214

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM