1

I have following classes

public class Project : IWorkflowDocument
{
    public string Id { get; set; }
    public Dictionary<Type, List<DenormalizedWorkflowReference<IWorkflowDocument>>> Parents { get; set; }
}

public class DenormalizedWorkflowReference<T> where T : IWorkflowDocument
{
    public string Id { get; set; }
    public string Name { get; set; }
    public static implicit operator DenormalizedWorkflowReference<T>(T doc)
    {
        return new DenormalizedWorkflowReference<T>
        {
            Id = doc.Id,
            Name = doc.Name
        };
    }
}

After storing a Project with some parents in the Db it looks as follows:

{
  "Name": "TestProject",
  "Parents": {
    "InterGrowth.Framework.MES.DomainObjects.Company, InterGrowth.Framework.MES.DomainObjects, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null": [
      {
        "Id": "companies/225",
        "Name": "Test Corporation"
      }
    ]
  },
  "Children": {
    "InterGrowth.Framework.MES.DomainObjects.Order, InterGrowth.Framework.MES.DomainObjects, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null": [
      {
        "Id": "orders/97",
        "Name": "Order_0"
      }
    ]
  }
}

What would be the right query to get a Project by over the parent property if the type and the Id is known? I tried following attempts unsucessfully:

var result = session.Query<Project>().Select(s => s.Parents[typeof (Company)]).Where(y => y.Any(u => u.Id == Company.Id));
var result = from project in session.Query<Project>() where project.Parents[typeof(Company)].Any(t=> t.Id == Company.Id) select project;
Martin
  • 21
  • 2

1 Answers1

0

The problem seems to be the way how Type is serialized and stored in the DB. After I changed Type to string the project class looks like:

public class Project : IWorkflowDocument
{
    public string Id { get; set; }
    public Dictionary<string, List<DenormalizedWorkflowReference<IWorkflowDocument>>> Parents { get; set; }
}

The following query works now:

var result = from project in session.Query<Project>() where project.Parents[typeof(Company).Name].Any(t=> t.Id == Company.Id) select project;
Martin
  • 21
  • 2