如何执行自定义查询并返回通用列表?

时间:2010-06-24 12:35:41

标签: c# castle-activerecord castle

我似乎只能找到如何从我的函数返回数组。这是我的模特:

[ActiveRecord("incident")]
public class Incident : ActiveRecordBase<Incident>
{
    public Incident() { }

    [PrimaryKey("id")]
    public int Id { get; set; }

    [Property("name")]
    public int Name { get; set; }
}

我目前正在使用SimpleQuery但是我不确定我是否应该使用HqlBasedQuery。这是我的通话功能:

 string query = @"select incident_id from Incident where incident_id = :incident_id";
 SimpleQuery<Incident> q = new SimpleQuery<Incident>(typeof(Incident), query);
 q.SetParameter("incident_id", _incidentId);
 q.SetQueryRange(1);

这有效,但我想要一个事件对象的通用列表。

谢谢。

1 个答案:

答案 0 :(得分:1)

T(T[])数组实现IList<T>,因此您已经 获取对象的通用列表:

string query = ...
IList<Incident> q = new SimpleQuery<Incident>(typeof(Incident), query).Execute();

如果要向该列表添加元素,请将其包装在另一个列表中:

IList<Incident> q = new List<Incident>(new SimpleQuery<Incident>(typeof(Incident), query).Execute());