我遇到一个问题,即我在查询时发出的index
是否会引发异常:
无法读取属性值:成员
以下是index
:
public class GroupsNameIdIndex : AbstractIndexCreationTask<CommunityDocument, GroupsNameIdIndex.Result>
{
public class Result
{
public string CommunityId { get; set; }
public string Id { get; set; }
public string Name { get; set; }
public IList<string> Members { get; set; }
}
public GroupsNameIdIndex()
{
Map = communities => from community in communities
from newGroup in community.Groups
select new
{
CommunityId = community.Id.Replace("CommunityDocuments/", string.Empty),
newGroup.Id,
newGroup.Name,
newGroup.Members
};
StoreAllFields(FieldStorage.Yes);
}
}
这是查询:
var groupResult = session
.Query<GroupsNameIdIndex.Result, GroupsNameIdIndex>()
.Where(x => x.CommunityId == info.Id)
.AsProjection<GroupsNameIdIndex.Result>()
.ToList();
我在文档中只有1
组,且相关Id
,且成员节点是空列表,而不是空。当我用一个字符串手动填充它时,查询运行正常。为什么不允许空列表?如果这是一个限制,它会使索引对我来说毫无意义,因为我会有很多空列表,只会让应用程序无处不在。
编辑:在有与之有关的情况下添加课程:
public class CommunityGroup
{
public CommunityGroup()
{
Members = new List<string>();
MemberDetails = new List<MemberView>();
MemberNames = new List<string>();
}
public string Id { get; set; }
public string Name { get; set; }
public string Slug { get; set; }
public string Description { get; set; }
public bool AdminOnly { get; set; }
public bool NewsContribute { get; set; }
public bool AutoGroup { get; set; }
public int LowerAgeLimit { get; set; }
public int UpperAgeLimit { get; set; }
public string Gender { get; set; }
public IList<string> Members { get; set; }
public IList<string> MemberNames { get; set; }
public IList<MemberView> MemberDetails { get; set; }
public string RelatedCommunityId { get; set; }
public string CreatedBy { get; set; }
public bool SmartGroup { get; set; }
public IList<SmartGroupRules> AndRules { get; set; }
public IList<SmartGroupRules> OrRules { get; set; }
public string ParentGroup { get; set; }
public List<string> EntryGroups { get; set; }
public bool Hidden { get; set; }
public string ActivityType { get; set; }
public List<string> AnyGroupList { get; set; }
public List<string> AllGroupList { get; set; }
public GroupType GroupType { get; set; }
}
这里是db
中组的json "Groups": [
{
"Id": "5ja34tefoq7sfj",
"Name": "new test",
"Slug": "new-test",
"Description": null,
"AdminOnly": true,
"NewsContribute": false,
"AutoGroup": false,
"LowerAgeLimit": 0,
"UpperAgeLimit": 0,
"Gender": null,
"Members": [],
"MemberNames": [],
"MemberDetails": [],
"RelatedCommunityId": null,
"CreatedBy": "Activity",
"SmartGroup": false,
"AndRules": null,
"OrRules": null,
"ParentGroup": null,
"EntryGroups": null,
"Hidden": false,
"ActivityType": null,
"AnyGroupList": null,
"AllGroupList": null,
"GroupType": "Default"
}
],