Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

331
Vistas
Entity Refresh - The refresh attempt has failed because an unexpected entity was returned by the data source

when I run a query in EF, the DbContext in it automatically caches the data that it retrieves from the database using query. In some cases it is helpful but I need to to hit database and get in which data changes outside the context. So I did some researches and I saw I need to refresh my dbcontext. I tried it bu it gives following error. How to fix this error?

The refresh attempt has failed because an unexpected entity was returned by the data source.

using (var ctx = new MyDbContext()){
..
var objContext = ((IObjectContextAdapter)ctx).ObjectContext;
var refreshEntities = ctx.ChangeTracker.Entries().Select(x => x.Entity).ToList();
objContext.Refresh(RefreshMode.StoreWins, refreshEntities);
..
}

Context;

 public MyDbContext() : base(OraConnection(), true) { }
             public DbSet<Books> Book{ get; set; }
             public DbSet<Libraries> Library{ get; set; }
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I ran into the same issue today. There was a trailing whitespace character in one of the fields in my dataset. That field also happened to be part of the EF Key. The trailing space was unexpected so I removed it in my dataset and the error went away.

I hope that your issue is just as straightforward.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda