How to execute custom query and return generic list?
I can only seem to find how to return arrays from my function. Here is my model:
[ActiveRecord("incident")]
public class Incident : ActiveRecordBase<Incident>
{
public Incident() { }
[PrimaryKey("id")]
public int Id { get; set; }
[Property("name")]
public int Name { get; set; }
}
I'm currently using SimpleQuery however I'm not sure if I should be using HqlBasedQuery instead. Here is my call function:
string query = @"select incident_id from Incident where incident_id = :incident_id";
Sim开发者_开发问答pleQuery<Incident> q = new SimpleQuery<Incident>(typeof(Incident), query);
q.SetParameter("incident_id", _incidentId);
q.SetQueryRange(1);
This works but I'd like a generic list of Incident objects.
Thank you.
An array of T (T[]
) implements IList<T>
so you already are getting a generic list of objects:
string query = ...
IList<Incident> q = new SimpleQuery<Incident>(typeof(Incident), query).Execute();
If you want to add elements to that list, wrap it in another list:
IList<Incident> q = new List<Incident>(new SimpleQuery<Incident>(typeof(Incident), query).Execute());
精彩评论