NHibernate标准问题

时间:2011-04-30 23:58:49

标签: nhibernate

我在hibernate中有一个查询:

string[] NewsId = new string[] {"ABC","DEF","GHI"};

public IEnumerable<News> NewsSelected(string[] NewsId)
    {

        List<ICriterion> criteria = new List<ICriterion>();
        criteria.Add(Restrictions.In("Id", NewsId));
        var results = _repository.GetByCriteria(criteria);
        return results;
    }

它返回零,但

public IEnumerable<News> NewsSelected(string[] NewsId)
    {

        List<ICriterion> criteria = new List<ICriterion>();
        criteria.Add(Restrictions.In("Id", new[]{"ABC","DEF","GHI"}));
        var results = _repository.GetByCriteria(criteria);
        return results;
    }

完美无缺。我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

您需要将查询参数复制到本地变量,如:

string[] NewsId = new string[] {"ABC","DEF","GHI"};

public IEnumerable<News> NewsSelected(string[] NewsId)
{
    var newsId = NewsId;

    List<ICriterion> criteria = new List<ICriterion>();
    criteria.Add(Restrictions.In("Id", newsId));
    var results = _repository.GetByCriteria(criteria);
    return results;
}