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

C# 如何执行自定义查询并返回通用列表?,c#,castle-activerecord,castle,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; }

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

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

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

    [Property("name")]
    public int Name { get; set; }
}
[ActiveRecord(“事件”)]
公共类事件:ActiveRecordBase
{
公共事件(){}
[主密钥(“id”)]
公共int Id{get;set;}
[财产(“名称”)]
公共int名称{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);
string query=@“从事件中选择事件id=:事件id”;
SimpleQuery q=新的SimpleQuery(事件类型,查询);
q、 SetParameter(“事件id”,包含);
q、 SetQueryRange(1);
这是可行的,但我想要一个事件对象的通用列表

谢谢。

一个T(
T[]
)数组实现了
IList
,因此您已经得到了一个对象的通用列表:

string query = ...
IList<Incident> q = new SimpleQuery<Incident>(typeof(Incident), query).Execute();
字符串查询=。。。
IList q=new SimpleQuery(typeof(Incident),query.Execute();
如果要向该列表中添加元素,请将其包装到另一个列表中:

IList<Incident> q = new List<Incident>(new SimpleQuery<Incident>(typeof(Incident), query).Execute());
IList q=new List(新的SimpleQuery(typeof(Incident),query.Execute());
一个T(
T[]
)数组实现了
IList
,因此您已经得到了一个对象的通用列表:

string query = ...
IList<Incident> q = new SimpleQuery<Incident>(typeof(Incident), query).Execute();
字符串查询=。。。
IList q=new SimpleQuery(typeof(Incident),query.Execute();
如果要向该列表中添加元素,请将其包装到另一个列表中:

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