Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

330
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!