开发者

How to execute custom query and return generic list?

开发者 https://www.devze.com 2023-01-04 19:36 出处:网络
I can only seem to find how to return arrays from my function. Here is my model: [ActiveRecord(\"incident\")]

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());
0

精彩评论

暂无评论...
验证码 换一张
取 消