I am indexing 2 different documents as below.
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; }
}
My query is as below. As you can see in Index
configuration that I mapped Name
property to DisplayName
but DisplayName
property is null
when the returning document is UserGroup
. When I review the fetched documents Name
property is not mapped to DisplayName
property and real value still stays on Name
property. How can I correctly transform that Name
property to DisplayName
property on UserGroup
?
_session.Query<SecurityObject, SecurityObjectIndex>()
.Where(s => s.DisplayName.StartsWith(searchTerm))
.ProjectFromIndexFieldsInto<SecurityObject>();
And here is my indexing configuration:
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
});
}
}