Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload(Async) does not fire PropertyChang(ing|ed) with Castle.Core-proxies #25229

Open
Tracked by #22954
AliveDevil opened this issue Jul 9, 2021 · 0 comments
Open
Tracked by #22954

Comments

@AliveDevil
Copy link

File a bug

According to #19340 Reload and ReloadAsync should fire PropertyChanged and PropertyChanging for entities implementing INotifyPropertyChanged and INotifyPropertyChanging respectively.

Though with EF Core 5.0 and the new Castle.Core-proxies implementation this does not happen anymore. With ReactiveUI this is especially cumbersome as I have to manually update states here now.

I created a sample reproduction repository: https://github.com/AliveDevil/efcore-reload (additionally attached as efcore-reload-main.zip).

Following is happening:

  • Print a.B?.Id (which is empty)
  • Subscribe to PropertyChanging and PropertyChanged-events
    • Those should print PropertyName to Console for Changing and Changed.
  • run LoadAsync on B-DbSet
    • Reprint a.B?.Id and observe that the Id has changed
  • run Entry(a).ReloadAsync() - atleast here PropertyChanged or PropertyChanging should be fired
  • reprint a.B?.Id and observe nothing has changed (between this and after LoadAsync)

Include verbose output

Running the app produces:

# Scenario 1 #
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
      Entity Framework Core 5.0.7 initialized 'AppDbContext' using provider 'Microsoft.EntityFrameworkCore.Sqlite' with options: using change tracking proxies 
warn: Microsoft.EntityFrameworkCore.Query[10103]
      The query uses the 'First'/'FirstOrDefault' operator without 'OrderBy' and filter operators. This may lead to unpredictable results.
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT "a"."Id", "a"."BId1"
      FROM "A" AS "a"
      LIMIT 1

info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT "b"."Id"
      FROM "B" AS "b"
1
Before Reload
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (3ms) [Parameters=[@__p_0='?'], CommandType='Text', CommandTimeout='30']
      SELECT "a"."Id", "a"."BId1"
      FROM "A" AS "a"
      WHERE "a"."Id" = @__p_0
      LIMIT 1
After Reload Reload
1
# Scenario 2 #
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
      Entity Framework Core 5.0.7 initialized 'AppDbContext' using provider 'Microsoft.EntityFrameworkCore.Sqlite' with options: using change tracking proxies 
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT "a"."Id", "a"."BId1"
      FROM "A" AS "a"
      LIMIT 1

info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
      Entity Framework Core 5.0.7 initialized 'AppDbContext' using provider 'Microsoft.EntityFrameworkCore.Sqlite' with options: using change tracking proxies 
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT "b"."Id"
      FROM "B" AS "b"

info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (1ms) [Parameters=[@__p_0='?'], CommandType='Text', CommandTimeout='30']
      SELECT "a"."Id", "a"."BId1"
      FROM "A" AS "a"
      WHERE "a"."Id" = @__p_0
      LIMIT 1
1

Observe that there is no entry starting with Changing or Changed.

I expect the proxies to implement basic change tracking themselves, and fire PropertyChanged and PropertyChanging accordingly.

Include provider and version information

EF Core version: 5.0.7
Database provider: Microsoft.EntityFrameworkCore.Sqlite
Target framework: .NET 5.0
Operating system: OS agnostic (observed on .NET Console macOS and .NET WPF Windows)
IDE: IDE agnostic (observed on Visual Studio for Mac 8.10.5 and Visual Studio 2019 16.10.3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants