【发布时间】:2018-06-09 11:33:48
【问题描述】:
如何为以下关系模式构建 NoSQL 模型和索引(最好用于 RavenDb v4)?
文档类型
Contact,其中每条记录可以有多个附加属性(属性类型在CustomField中定义,值在ContactCustomField中定义)
考虑到需要对一个查询中突出显示的字段(联系人中的所有字段加上自定义字段)进行过滤/排序。
我看到的可能选项:
选项 #1
当然,我会想象以下持久模型:
public class Contact
{
public string Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
// Where the key is CustomField.Id and the value is ContactCustomField.Value
public Dictionary<string, string> CustomValues { get; set; }
}
public class CustomField
{
public string Id { get; set; }
public string Code { get; set; }
public string DataType { get; set; }
public string Description { get; set; }
}
但是,为如下查询构建索引(对不起,混合语法)让我感到困惑:
SELECT Name, Address, Phone, CustomValues
FROM Contact
WHERE Name LIKE '*John*' AND CustomValues.Any(v => v.Key == "11" && v.Value == "student")
选项 #2
另一种方法是保持标准化结构(如上图所示)。然后它就可以工作了——我只需要在Contact的查询中包含ContactCustomField。
缺点是没有利用 NoSQL 的好处。
【问题讨论】:
标签: c# indexing nosql ravendb ravendb4