dbroudy / LazyEntityGraph

LazyEntityGraph is an open source library for .NET which lets you generate object graphs with circular dependencies, such as those found in ORMs, by lazily generating relationship properties.
MIT License
27 stars 12 forks source link

Does not work with EF.Core 3. if you don't explicitly add a reference to Microsoft.EntityFrameworkCore.InMemory 3 #23

Closed nlz242 closed 1 year ago

nlz242 commented 4 years ago

Using Entity Framework Core 3.1.5, if I add LazyEntityGraph.EntityFrameworkCore to my project, it pulls Microsoft.EntityFrameworkCore.InMemory 2.0.0, which is not compatible with 3.1.* (Probablaly 3.0 too). It crashes on the following code, of LazyEntityGraph.EntityFrameworkCore\ModelMetadataGenerator.cs with an exception that says "Method 'get_Info' in type InMemoryOptionsExtension not implemented"

 var options = new DbContextOptionsBuilder<TContext>()
                .UseInMemoryDatabase(databaseName: "App=EntityFrameworkCore")
                .Options;

Work-around is to explicitly add a reference to Microsoft.EntityFrameworkCore.InMemory (installing the nuget package) to the matching version (3.1.5, in my case).

While I'm not sure how this can be fixed in the code/builds/packages themselves, I think it should at least be documented on the Wiki, the Front-page or the Getting Stated.

dbroudy commented 4 years ago

@nlz242 Thanks for reporting this. The Info method is unfortunately a breaking change in EFCore 3.0: https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/breaking-changes#extension-infometadata-has-been-removed-from-idbcontextoptionsextension

I've been attempting to support EFCore 2.0 and 3.0 (or 2.1 and 3.1 since those are the LTS releases) from the same code base, but may be more trouble than it's worth. It's a shame, because the in memory database isn't used for any sort of storage, just to satisfy the configuration's requirement for a database provider. Some kind of conditional dependency would solve it, but those only depend on target frameworks, not versions of other packages.

In any case, glad you have a workaround for now, and I'll look at switching the dependency to EFCore 3.1 pretty soon I think.

techdragon commented 1 year ago

Whats the current best way to solve this two years on?

We're now up to EFCore 6 and 7 and I don't feel my dotNet skills are up to maintaining a fork of a library like this, so I'd really prefer a new release with updates to support newer versions of Entity Framework Core.

Note: the workaround does still work... but over time it makes less and less sense to support the older versions of EFCore that is the root cause of this issue.

nlz242 commented 1 year ago

As far as I am concerned, the workaround was good enough. This is no longer an issue for me as I have since moved on to other projects, two and a half years later. Feel free to close! Thanks!