1
我正在索引2個不同的文檔,如下所示。將不同的文檔索引到RavenDb中的同一對象
public class User
{
public UserId UserId { get; set; }
public string DisplayName { get; set; }
}
public class UserGroup
{
public UserGroupId UserGroupId { get; set; }
public string Name { get; set; }
}
//this is for indexing result
public class SecurityObject
{
public virtual Guid Id { get; set; }
public virtual string DisplayName { get; set; }
public virtual SecurityObjectType ObjectType { get; set; }
}
我的查詢如下。正如您在Index
配置中看到的那樣,我將Name
屬性映射到DisplayName
,但DisplayName
屬性爲null
,當返回文檔是UserGroup
時。當我檢查提取的文件Name
屬性未映射到DisplayName
屬性和實際值仍然停留在Name
屬性。如何正確地將Name
財產轉換爲財產UserGroup
?
_session.Query<SecurityObject, SecurityObjectIndex>()
.Where(s => s.DisplayName.StartsWith(searchTerm))
.ProjectFromIndexFieldsInto<SecurityObject>();
這裏是我的索引配置:
public class SecurityObjectIndex
: AbstractMultiMapIndexCreationTask<SecurityObject>
{
public override string IndexName
{
get
{
return "UserAndUserGroup/SecurityObjectIndex";
}
}
public SecurityObjectIndex()
{
AddMap<User>(users => from u in users
select new
{
DisplayName = u.DisplayName,
ObjectType = SecurityObjectType.Users
});
AddMap<UserGroup>(userGroups => from u in userGroups
select new
{
DisplayName = u.Name,
ObjectType = SecurityObjectType.Groups
});
}
}