1

我有以下课程

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
        };
    }
}

在 Db 中存储带有一些父母的项目后,它如下所示:

{
  "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"
      }
    ]
  }
}

如果类型和 ID 已知,那么通过父属性获取项目的正确查询是什么?我尝试了以下尝试,但均未成功:

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;
4

1 回答 1

0

问题似乎是 Type 如何序列化并存储在数据库中的方式。在我将类型更改为字符串后,项目类如下所示:

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

以下查询现在有效:

var result = from project in session.Query<Project>() where project.Parents[typeof(Company).Name].Any(t=> t.Id == Company.Id) select project;
于 2013-10-26T08:14:46.783 回答