RavenDB结果变压器没有完全填充结果

时间:2014-12-03 05:56:46

标签: ravendb

我已经设置了以下RavenDB“Result Transformer”来操作下面包含的模型并输出如下定义的结果类。执行查询时一切正常,但结果类中的VoicemailMessageHeader中的“Id”字段未填充。 VoicemailMessageHeader中的所有其他字段都会填充。为什么“Id”字段不会被填充?

结果变形金刚:

public class VoicemailMessageHeaderWithDisplayNameTransformer : AbstractTransformerCreationTask<VoicemailMessageHeader>
{
  public VoicemailMessageHeaderWithDisplayNameTransformer()
  {
    TransformResults = voicemailMessageHeaders => from voicemailMessageHeader in voicemailMessageHeaders
       let displayNameRecord = LoadDocument<DisplayName>(voicemailMessageHeader.CallerPhoneNumber)
       let displayName = (displayNameRecord != null) ? displayNameRecord.Name : string.Empty
       select new{
         VoicemailMessageHeader = voicemailMessageHeader,
         DisplayName = displayName,
       };
   }
 }

转换的数据库对象:

public class VoicemailMessageHeader
{
        public string Id { get; set; }
        public string OwnerId { get; set; }
        public string FolderId { get; set; }
        public string CallerName { get; set; }
        public string CallerPhoneNumber { get; set; }
        public string AccountNumber { get; set; }
        public DateTime CallDateTime { get; set; }
        public TimeSpan Duration { get; set; }
        public string MessageUrl { get; set; }
        public bool IsListened { get; set; }
        public bool IsDeleted { get; set; }
        public bool IsDownloaded { get; set; }
        public string MessageFilePath { get; set; }
}

由变换器创建的结果类:

public class VoicemailMessageHeaderWithDisplayName
{
        public VoicemailMessageHeader VoicemailMessageHeader { get; set; }
        public string DisplayName { get; set; }
}

查询:

session.Query<VoicemailMessageHeader>()
  .TransformWith<RavenDbIndexes.VoicemailMessageHeaderWithDisplayNameTransformer,
    VoicemailMessageHeaderWithDisplayName>()

0 个答案:

没有答案