TurnerSoftware / MongoFramework

An "Entity Framework"-like interface for MongoDB
MIT License
392 stars 35 forks source link

Not able to access context in run time #341

Closed DMGlion closed 1 year ago

DMGlion commented 1 year ago

I am able to seed a database and populate with an admin tool, console application.

When I am seeding the database I am also able to query collections no issue: _contextSeedModel.Find(id), I am getting the expected results no problem.

When I am trying to execute the run time, I am getting an exception, I am using the same repository, context and models.

$exception : {"Object reference not set to an instance object"} Data: {System.Collection.ListDictionaryInternal} Message: Object reference not set to an instance of an object. Source: MongoFramework StactTrace: at MongoFramework.Infrastructure.Linq.MongoFrameworkQueryProvider1.GetExecutionModel(Expression expression, Boolean isAsync) at MongoFramework.Infrastructure.Linq.MongoFrameworkQueryProvider1.Execute(Expression expression) at MongoFramework.Infrastructure.Linq.MongoFrameworkQueryProvider1.Execute[TResult](Expression expression) at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable1 source, Expression`1 predicate) at AnalogDevices.XPP.PublicWeb.Platform.Persistence.Repositories.CosmosShopRepository.GetShopByName(String shopName) in C:\Users\dmoya\Project\PB\interface\Shop.Persistence\Repositories\CosmosShopRepository.cs:line 46

Turnerj commented 1 year ago

What version of MongoDB and the MongoDB driver are you using?

DMGlion commented 1 year ago

Hi @Turnerj I am using the version 2.19.0 MongoDB.Driver, 0.27.0 for MongoFramework and 0,27 for MongoFramework.Profiling.MiniProfiler.

DMGlion commented 1 year ago

Hi @Turner I got it working, For a certain reason I was getting the error because on the app web side I was running this 2 nuggets:

    <PackageReference Include="MongoDB.Driver" Version="2.19.0" />
    <PackageReference Include="MongoDB.Driver.Core" Version="2.19.0" />

I removed MongoDB.Driver and now is working like a charm. Anyone knows why thius 2 libraries together make the queries to fail?

Turnerj commented 1 year ago

The issue is with the v2.19.0 version of the MongoDB driver. They have a new internal LINQ provider which is affecting MongoFramework. Fortunately there is a way currently to set it back to the original provider which v0.28.0 of MongoFramework (which I just released) works around.

Try upgrading to MongoFramework v0.28.0 and it should solve your issue.