मैं एक डेटाटाइम पर RavenDB से पूछताछ करने की कोशिश कर रहा हूं जिसे संग्रह में प्रवेश से ऑफसेट किया जा रहा है। जैसा कि नीचे दिखाया गया है, मेरे पास एक अपॉइंटमेंट रिमाइंडर ऑब्जेक्ट है जिसमें कई अपॉइंटमेंट रिमेन्डर जॉब्स हैं। मैं AppointmentReminders के लिए पूछना चाहता हूं जहां AppointmentReminderJob चलाने के कारण है।संग्रह ऑफ़सेट में मूल्य के साथ डेटाटाइम पर RavenDB क्वेरी
मेरे मॉडल इस प्रकार हैं:
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 जो चलाने के लिए (मैं इस कहां खंड पूरा नहीं हुआ है पता है वर्तमान नौकरी की सूची प्राप्त करने का प्रयास है, लेकिन मैं करने के लिए कोशिश की है कोई भाग्य के साथ इसे सरल):
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);
मेरे आखिरी सवाल के बारे में इस होगा, मेरी नक्शा/सूचकांक निश्चित रूप से उसी दस्तावेज़ आईडी (upgradereminder) की कई प्रविष्टियों में परिणाम हो सकता है, लेकिन मेरी परिणामी सूची में दस्तावेज़ का केवल 1 उदाहरण होता है। मैं काम करने के तरीके से खुश हूं, मुझे यकीन नहीं है कि मुझे अपने कोड में कुछ और कम करना चाहिए या सिर्फ रावेन को इसे संभालने दें जैसे ऐसा लगता है?
धन्यवाद! आपने मुझे सही दिशा में इंगित किया। मैंने अपने प्रश्न को उस कोड के साथ संपादित किया है जिसने मुझे काम किया है। मैंने सर्वोत्तम प्रथाओं के बारे में एक सवाल जोड़ा, मैं उम्मीद नहीं कर रहा था कि रावेन केवल मेरे दस्तावेज़ के 1 उदाहरण लौटाएगा, भले ही मेरे इंडेक्स में कई प्रविष्टियां हों, जो कि सभी खंडों को इंगित करते हैं, जहां सभी एक ही दस्तावेज़ को इंगित करते हैं। मुझे यकीन नहीं है कि मुझे मदद करने के लिए कुछ और करना चाहिए या सिर्फ रेवेन को प्रत्येक दस्तावेज़ के एक उदाहरण को वापस करने के लिए जानना जारी रखना चाहिए। – mcbowes