0

i am looking for a way of refreshing Entities that changed in the Database. The Entities i want to refresh have a RowVersion [TimeStamp] Property. What i wanna do is refresh all my loaded Entities where the RowVersion in the database is greater (younger) than my loaded entities.

Here my entity class:

 public class Template : ICloneable, IDisposable
{
    public int Id                               { get; set; }
    public int InternalId                       { get; set; }
    public int Order                            { get; set; }
    public string Group                         { get; set; }
    public string Description                   { get; set; }
    public string Root                          { get; set; }

    public string Owner                         { get; set; }

    [Timestamp]
    public byte[] RowVersion                    { get; set; }

}

So far i use this code to refresh my entities:

Remoting.Context.ObjectContext.RefreshAsync(System.Data.Entity.Core.Objects.RefreshMode.StoreWins, Entities);

Right now every entity is refreshed which maybe causes performance issues if there are many of them. Therefore i thought it would be better to only refresh the entities where the rowversion is different. How can i do that?

  • Possible duplicate of [Entity Framework Refresh context?](https://stackoverflow.com/questions/20270599/entity-framework-refresh-context) – samtrion Dec 04 '18 at 12:22
  • @MartinS. it's not a real duplicate i think, as i cannot find a way to compare the RowVersion Timestamps? –  Dec 04 '18 at 12:40
  • [Look at this answer](https://stackoverflow.com/a/31431605/10574963) This will update all Entities based on changes like RowVersion – samtrion Dec 04 '18 at 12:46
  • @MartinS.yes, but it also reloads the entry even if no changes happend (same rowversion). Therefore i tought i have to compare the rowversion first before reloading the entry to avoid useless reloads. –  Dec 04 '18 at 12:50
  • @ManuelBleimuth the call you are trying to save there is a simple setter. Unless you encapsulate all of your BL into your setter, reloading the entry in any case is fine. – DevilSuichiro Dec 04 '18 at 14:00
  • @DevilSuichiro, ok, so you are saying there should not be any impact on performance? I will try it. –  Dec 04 '18 at 14:27

0 Answers0