I am trying to join two MongoDB collections by using MongoDB Provider but Id field is "ObjectId" type and ProjectId is "String". I think because of that I got an error which I shared below. How can I fix that issue?
var projects = database.GetCollection<TrckTrace.Shared.Models.Common.Project>("project").AsQueryable();
var tasks = database.GetCollection<TrckTrace.Shared.Models.Common.Task>("task").AsQueryable();
var database = client.GetDatabase("trcktrace");
var projects = database.GetCollection<TrckTrace.Shared.Models.Common.Project>("project").AsQueryable();
var tasks = database.GetCollection<TrckTrace.Shared.Models.Common.ScrapingTask>("task").AsQueryable();
var query = from project in projects
join task in tasks
on project.Id.ToString() equals task.ProjectId
into joined
select new
{
Id = project.Id,
Name = project.Name,
Tasks = joined
};
var res = query.ToList();
System.NotSupportedException HResult=0x80131515 Message=Unable to determine the serialization information for the outer key selector in the tree: aggregate([]).GroupJoin(aggregate([]), project => project.Id.ToString(), task => task.ProjectId, (project, matchedProjects) => new <>f__AnonymousType2
3(Id = project.Id, Name = project.Name, Tasks = matchedProjects)) Source=MongoDB.Driver
1 arguments) at MongoDB.Driver.Linq.Processors.MethodInfoMethodCallBinder
StackTrace: at MongoDB.Driver.Linq.Processors.Pipeline.MethodCallBinders.JoinBinder.Bind(PipelineExpression pipeline, PipelineBindingContext bindingContext, MethodCallExpression node, IEnumerable1.Bind(PipelineExpression pipeline, TBindingContext bindingContext, MethodCallExpression node, IEnumerable
1 arguments) at MongoDB.Driver.Linq.Processors.PipelineBinderBase1.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.MongoQueryProviderImpl1.Translate(Expression expression) at MongoDB.Driver.Linq.MongoQueryProviderImpl
1.Execute(Expression expression) at MongoDB.Driver.Linq.MongoQueryableImpl2.GetEnumerator() at System.Collections.Generic.List
1.AddEnumerable(IEnumerable1 enumerable) at System.Linq.Enumerable.ToList[TSource](IEnumerable
1 source) at DataMigration.DataMigration.d__5.MoveNext() in C:\Users\User01\Source\Repos\RabbitMQTest\DataMigration\DataMigration.cs:line 166 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at DataMigration.Program.d__0.MoveNext() in C:\Users\User01\Source\Repos\RabbitMQTest\DataMigration\Program.cs:line 23 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at DataMigration.Program.(String[] args)
User contributions licensed under CC BY-SA 3.0