Reputation: 7144
I'm trying to get all records of specific type from RavenDB with C#.
When I'm using Lucene:
var serviceTraces = session.Advanced.LuceneQuery<ServiceTrace>("IDLoadDateIndex").Take(50);
I'm getting the results in:
serviceTraces.QueryResult.Results
When I'm not using Lucene:
var serviceTraces = session.Query<ServiceTrace>("IDLoadDateIndex").Take(50);
I'm not getting any results and an exception is thrown when trying to perform "ToList()" on "serviceTraces" object.
Why is that ?
UPDATE:
ServiceTrace class:
public class ServiceTrace
{
public ServiceTrace(ServiceDeployment sd)
{
// TODO: Complete member initialization
this.ServiceDeploymentID = sd.Id;
}
public string Id { get; set; }
public string TransactionID { get; set; }
public string ParentTransactionID { get; set; }
public string RequestID { get; set; }
public int ApplicationCode { get; set; }
public int InstituteCode { get; set; }
public string ServiceDeploymentID { get; set; }
public string UserHostAddress { get; set; }
public string UserAgent { get; set; }
public string Username { get; set; }
public DateTime RequestDateTime { get; set; }
public DateTime ResponseDateTime { get; set; }
public string RequestBody { get; set; }
public string ResponseBody { get; set; }
public string Key1Value { get; set; }
public string Key2Value { get; set; }
public string Key3Value { get; set; }
public string Key4Value { get; set; }
public string Key5Value { get; set; }
public int StatusCode { get; set; }
public string StatusDescription { get; set; }
public string FullExceptionText { get; set; }
public DateTime LoadDate { get; set; }
public DateTime ActivationDateTime { get; set; }
public string HostAddress { get; set; }
public string BpmID { get; set; }
public DateTime PreProcessDatetime { get; set; }
public string DestHostAddress { get; set; }
public string ArchivePath { get; set; }
public string BTInstanceID { get; set; }
public string Temp1 { get; set; }
public string ExternalComponentDuration { get; set; }
public string SQLIdentity { get; set; }
public string ExceptionCode { get; set; }
public string CertificateID { get; set; }
public string ExternalComponentType { get; set; }
public string ActivationID { get; set; }
}
IDLoadDateIndex:
public class IDLoadDateIndex : AbstractIndexCreationTask<ServiceTrace>
{
public IDLoadDateIndex()
{
Map = serviceTrace => from st in serviceTrace
select new { LoadDate = st.LoadDate };
Index(x => x.LoadDate, FieldIndexing.Analyzed);
}
}
Upvotes: 0
Views: 65
Reputation: 7144
The solution is to add a default constructor:
public ServiceTrace()
{
}
because when getting the data from RavenDB, the engine initialize a new instance by:
public ServiceTrace(ServiceDeployment sd)
{
// TODO: Complete member initialization
this.ServiceDeploymentID = sd.Id;
}
and the ServiceDeployment object is a null reference .
Upvotes: 1
Reputation: 22956
In both cases, you need to call ToList on the serviceTraces
Upvotes: 0