6

コレクション内のエントリによってオフセットされている Datetime で RavenDB をクエリしようとしています。以下に示すように、多くの AppointmentReminderJobs を含む AppointmentReminder オブジェクトがあります。AppointmentReminderJob が実行される予定の AppointmentReminders を照会したいと思います。

私のモデルは次のとおりです。

public class AppointmentReminder
{
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Email { get; set; }
    public string Phone { get; set; }
    public DateTime AppointmentDateTime { get; set; }
    public ReminderStatus ReminderStatus { get; set; }
    public List<AppointmentReminderJob> AppointmentReminderJobs { get; set; }
 }

public class AppointmentReminderJob
{
    public JobStatus JobStatus { get; set; }
    public int DaysPrior { get; set; }
}

私のコントローラーと、実行する現在のジョブがある AppointmentReminders のリストを取得しようとします (この Where 句が完全ではないことはわかっていますが、単純化しようとしましたが、うまくいきませんでした):

public ActionResult GetJobsQueuedListCurrent()
    {
        var jobsqueuedlist = RavenSession.Query<AppointmentReminder>()
            .Where(appointmentreminder => appointmentreminder.AppointmentReminderJobs.Any(x => appointmentreminder.AppointmentDateTime < DateTime.Now.AddDays(x.DaysPrior)))
            .OrderBy(appointmentreminder => appointmentreminder.AppointmentDateTime)
            .Take(20)
            .ToList();

        return View("List", jobsqueuedlist);

    }

上記を呼び出すと、次の応答が得られます。

variable 'x' of type 'ProjectName.Models.AppointmentReminderJob' referenced from scope '', but it is not defined

次のようにインデックスを設定しようとしています。

public class JobsQueuedListCurrent : AbstractIndexCreationTask<AppointmentReminder, JobsQueuedListCurrent.IndexResult>
{
    public class IndexResult
    {
        public int Id { get; set; }
        public DateTime JobDateTime { get; set; }
    }

    public JobsQueuedListCurrent()
    {


        Map = appointmentreminders => from appointmentreminder in appointmentreminders
                                      from job in appointmentreminder.AppointmentReminderJobs
                                      select new 
                                      { 
                                          Id = appointmentreminder.Id, 
                                          JobDateTime = appointmentreminder.AppointmentDateTime.AddDays(job.DaysPrior)
                                      };
        Store(x => x.Id, FieldStorage.Yes);
        Store(x => x.JobDateTime, FieldStorage.Yes);
    }
}

現在、次を使用してクエリを実行し、期待される結果を取得しています。

var jobsqueuedlist = RavenSession.Query<JobsQueuedListCurrent.IndexResult, JobsQueuedListCurrent>()
            .Where(x=>x.JobDateTime >= DateTime.Now)
            .As<AppointmentReminder>()
            .Take(20)
            .ToList();

        return View("List", jobsqueuedlist);

これに関する私の最後の質問は、私のマップ/インデックスは間違いなく同じドキュメント ID (予定リマインダー) の複数のエントリになる可能性がありますが、結果のリストにはドキュメントのインスタンスが 1 つしか含まれていないということです。私はそれが機能する方法に満足しています.reduceを実行するか、コードで何か他のことを行うべきか、それともRavenに処理させているかのように処理させるべきかどうかはわかりません.

4

1 に答える 1

5

このようなクエリは作成できません。これには、RavenDB がクエリ中に計算を実行する必要があり、これは許可されていません。RavenDB では、インデックス内のデータに対するクエリのみが許可されます。

できることは、インデックスで計算をセットアップし、それに対してクエリを実行することです。

于 2012-11-01T08:00:34.743 に答える