-1

在 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'

谢谢

4

2 回答 2

1

如果我没记错的话,该查询将返回一个object[]. 所以你需要做

int totalAmount = resultList[i][0];
string myCode= resultList[i][1];
于 2012-06-28T21:17:59.693 回答
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
 }
于 2012-06-28T21:56:42.657 回答