Я использую официальный строго типизированный драйвер C # MongoDb версии 2.8.0 для взаимодействия с MongoDB.
Когда я пытаюсь присоединиться к коллекции mongodb типа Meals со списком типа MealsRequest, я получаю следующее исключение: -
System.NotSupportedException: The joined collection cannot have any qualifiers."
Вот мой код: -
public class Meal
{
[BsonId]
[BsonRepresentation(representation: BsonType.ObjectId)]
public string Id { get; set; }
public string RestaurantId { get; set; }
public string Category { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public int Calories { get; set; }
public string Photo { get; set; }
}
public class MealRequest
{
[BsonId]
[BsonRepresentation(representation: BsonType.ObjectId)]
public string Id { get; set; }
[Required(ErrorMessage = "This field is required")]
public string MealId { get; set; }
[Required(ErrorMessage = "This field is required")]
public int Count { get; set; }
public decimal Price { get; set; }
public decimal MealTotal { get; set; }
public string Name { get; set; }
}
И это код, который выдает исключение: -
var mealsRequests = await repository.Meals.AsQueryable()
.Join(inner: mealsRequests, outerKeySelector: m => m.Id, innerKeySelector: mr => mr.MealId,
resultSelector: (m, mr) => new MealRequest()
{
Id = mr.Id,
MealId = m.Id,
Count = mr.Count,
Price = m.Price,
Name = m.Name,
}).ToListAsync();//Exception happens at this line
return mealsRequests;
А это трассировка стека: -
System.NotSupportedException: The joined collection cannot have any qualifiers.
at MongoDB.Driver.Linq.Processors.Pipeline.MethodCallBinders.JoinBinder.Bind(PipelineExpression pipeline, PipelineBindingContext bindingContext, MethodCallExpression node, IEnumerable`1 arguments)
at MongoDB.Driver.Linq.Processors.MethodInfoMethodCallBinder`1.Bind(PipelineExpression pipeline, TBindingContext bindingContext, MethodCallExpression node, IEnumerable`1 arguments)
at MongoDB.Driver.Linq.Processors.PipelineBinderBase`1.BindMethodCall(MethodCallExpression node)
at MongoDB.Driver.Linq.Processors.Pipeline.PipelineBinder.Bind(Expression node, IBsonSerializerRegistry serializerRegistry)
at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Prepare(Expression expression)
at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Translate(Expression expression)
at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
at MongoDB.Driver.Linq.MongoQueryableImpl`2.ToCursorAsync(CancellationToken cancellationToken)
at MongoDB.Driver.IAsyncCursorSourceExtensions.ToListAsync[TDocument](IAsyncCursorSource`1 source, CancellationToken cancellationToken)
В чем причина этого исключения? И как это решить?