EventFlow icon indicating copy to clipboard operation
EventFlow copied to clipboard

EFCore 6 support (Missing method exception)

Open AlsenDev opened this issue 4 years ago • 9 comments

I get this exception when trying to call PublishAsync() from the CommandBus. It seems to be a problem that occurs when using EFCore 6. I got this exception while using EFCore 6.0.0-preview.7 with the newest version of EventFlow, but I get the same error on RC 2.

System.MissingMethodException: Method not found: 'Microsoft.EntityFrameworkCore.Metadata.IEntityType Microsoft.EntityFrameworkCore.ModelExtensions.FindEntityType(Microsoft.EntityFrameworkCore.Metadata.IModel, System.Type)'.
   at EventFlow.EntityFramework.ReadStores.EntityFrameworkReadModelStore`2.EntityDescriptor..ctor(DbContext context, IApplyQueryableConfiguration`1 queryableConfiguration)
   at EventFlow.EntityFramework.ReadStores.EntityFrameworkReadModelStore`2.<>c__DisplayClass16_0.<GetDescriptor>b__0(String s) in EventFlow.EntityFramework.dll:token 0x60000a7+0x0
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) in System.Collections.Concurrent.dll:token 0x60000d3+0x10
   at EventFlow.EntityFramework.ReadStores.EntityFrameworkReadModelStore`2.GetDescriptor(DbContext context, IApplyQueryableConfiguration`1 queryableConfiguration) in EventFlow.EntityFramework.dll:token 0x600003d+0x35
   at EventFlow.EntityFramework.ReadStores.EntityFrameworkReadModelStore`2.GetAsync(TDbContext dbContext, String id, CancellationToken cancellationToken, Boolean tracking) in EventFlow.EntityFramework.dll:token 0x600003a+0x0
   at EventFlow.EntityFramework.ReadStores.EntityFrameworkReadModelStore`2.UpdateReadModelAsync(TDbContext dbContext, IReadModelContextFactory readModelContextFactory, Func`5 updateReadModel, CancellationToken cancellationToken, ReadModelUpdate readModelUpdate) in EventFlow.EntityFramework.dll:token 0x600003c+0xc6
   at EventFlow.Core.TransientFaultHandler`1.<>c__DisplayClass4_0.<<TryAsync>b__0>d.MoveNext() in EventFlow.dll:token 0x60009af+0x77
--- End of stack trace from previous location ---

I don't know if EFCore 6 support is planned yet, but I thought I at least should mention this error.

AlsenDev avatar Nov 01 '21 07:11 AlsenDev

I suspect this is due to framework targeting / version reference issues in the EventFlow.EntityFramework project; I found that EF Core 6 works if you register a new service with implementation of IEntityFrameworkReadModelStore<TReadModel> using the exact same code in the repo then it works fine. Only seems to be the read store side that's affected.

rthomson83 avatar Mar 29 '22 21:03 rthomson83

Is there an update on this? I cannot get it figured out and it is blocking me hard.

jessemillerrev avatar Jul 11 '22 17:07 jessemillerrev

You have to target EntityFrameworks nuget packages with version 5.X.X to have it working. Seems it won't be fixed in EventFlow 0.X but only in 1.X

jutimor avatar Jul 11 '22 18:07 jutimor

I solved this by implementing my own EntityFrameworkReadModel service so it will use the EF version that my project uses instead of EventFlow as was suggested by @rthomson83 above. Even implemented its own extension method for UseEntityFrameworkReadModel. This is working perfectly and when/if this gets fixed in 1.X it should be simple to point back to the EventFlow version.

jessemillerrev avatar Jul 11 '22 19:07 jessemillerrev

@jessemillerrev do you have an example? I'm struggling with the same issue now..

nZeus avatar Jul 12 '22 14:07 nZeus

@jessemillerrev do you have an example? I'm struggling with the same issue now..

Start by adding a new store like this one: https://github.com/rthomson83/eventflow-ef-core-fix/blob/main/EntityFrameworkCoreReadModelStore.cs

Then you can create a new extension method to make using it easier: https://github.com/rthomson83/eventflow-ef-core-fix/blob/main/EFReadStoreExtensions.cs

Finally use/register the service via autofac however you are using that. For me it was a module that has all the EF configuration for eventflow read store side: https://github.com/rthomson83/eventflow-ef-core-fix/blob/main/ReadStoreModule.cs

rthomson83 avatar Jul 12 '22 15:07 rthomson83

@rthomson83 I wish I had those links before I figured it all out! Thanks for posting that, hopefully others will benefit from your awesome work there.

jessemillerrev avatar Jul 12 '22 16:07 jessemillerrev

Thank you very much @rthomson83 for the snippets. I've just checked and your implementation indeed solves the problem. Although I'm not sure if we can use this on production :(, unfortunately. I also noticed that it generates the wrong Version number (0 instead of 1)...

Thanks again!

nZeus avatar Jul 12 '22 20:07 nZeus

Thank you very much @rthomson83 for the snippets. I've just checked and your implementation indeed solves the problem. Although I'm not sure if we can use this on production :(, unfortunately. I also noticed that it generates the wrong Version number (0 instead of 1)...

Thank again!

No worries, I did notice that with the version but it does increment. I've not changed anything in the store (that's the original code from the event flow repo). I'm pretty sure the version is like that because its not been set default in the read model property Version, defined with the ConcurrencyCheck attribute. If you start it at 1 it would increment from there.

rthomson83 avatar Jul 12 '22 20:07 rthomson83

Hello there!

We hope you are doing well. We noticed that this issue has not seen any activity in the past 90 days. We consider this issue to be stale and will be closing it within the next seven days.

If you still require assistance with this issue, please feel free to reopen it or create a new issue.

Thank you for your understanding and cooperation.

Best regards, EventFlow

github-actions[bot] avatar Apr 08 '23 13:04 github-actions[bot]

Hello there!

This issue has been closed due to inactivity for seven days. If you believe this issue still needs attention, please feel free to open a new issue or comment on this one to request its reopening.

Thank you for your contribution to this repository.

Best regards, EventFlow

github-actions[bot] avatar Apr 16 '23 09:04 github-actions[bot]