NHibernate,如何循环并获得结果?

时间:2012-06-28 21:10:34

标签: c# nhibernate

在NHibernate中,如何循环并获得结果?例如,如何获得'totalAmount'和'MY_CODE'?

var criteria = Session.CreateCriteria<MyClass>();
ProjectionList projectionList = Projections.ProjectionList();
projectionList.Add(Projections.RowCount(), "totalAmount");
projectionList.Add(Projections.GroupProperty("MY_CODE"));
criteria.SetProjection(projectionList);

var resultList = criteria.List();
// how to get 'totalAmount' and 'MY_CODE'

由于

2 个答案:

答案 0 :(得分:1)

如果我没错,查询将返回object[]列表。所以你需要做

int totalAmount = resultList[i][0];
string myCode= resultList[i][1];

答案 1 :(得分:0)

你可以做出“如何循环并获得结果”:

 var total = 0;
 var code = "";
 foreach(var result in resultList)
 {
      total = result[0]; // or result["totalAmount"]
      code = result[1];  // or result["my_code"]
      //then do something with em
 }