Conversion from ICollection<Model> to List<Model> fails with Exception for LINQV3 Provider

Hi

I am getting MongoDb.Driver.Linq.ExpressionNotSupported exception when trying to convert a collection into a list and it started to happen when I upgraded the MongoDbDriver to 2.19 and above.

When I tried using LinqV2 provider then my code works fine. Below is the snippet over which I am getting the error:

Repo.Get().Select(x => new Model
{
Property = (List)x.Property1
}
)

Here is Property is type of List and x.Property is of type ICollection

Below is the error:
MongoDB.Driver.Linq.ExpressionNotSupportedException: Expression not supported: Convert(x.Property, List1) because conversion to System.Collections.Generic.List1[Model.NewModel] is not supported

Could you please let me know by when it is going to be supported as I didn’t found any solution for it yet.

Hi @Prakher_Mehrotra,

Welcome to MongoDB Community forums. Are you simply trying to convert a collection to a list? You can try something like var restaurantsList = _restaurantsCollection.AsQueryable<Restaurant>().ToList() If you would like to continue using LINQ2, you can switch to the LINQ2 provider using the steps seen here. However, please note that the LINQ2 provider will be deprecated in the next major version of the driver. Hope that helps.

Thanks,

Rishit.