1
 List<object[]> products = GetSession().CreateCriteria<Product>()
            .SetProjection(Projections.ProjectionList()
                               .Add(Projections.Property("Id"))
                               .Add(Projections.Property("Name"))
                               .Add(Projections.Property("Price"))
             )
             .List();
public class ProductRow
{
     public int Id { get; set; }
     public string Name { get; set; }
     public double Price { get; set; }
}

List <ProductRow>タイプとして結果を取得するにはどうすればよいですか?

Projection.Cast関数があるようですが、その使用方法に関するドキュメントはありません。

4

1 に答える 1

3

結果トランスフォーマーを設定してみてください:

var result = GetSession()
    .CreateCriteria<Product>()
    .SetProjection(Projections.ProjectionList()
        .Add(Projections.Property("Id"), "Id")
        .Add(Projections.Property("Name"), "Name")
        .Add(Projections.Property("Price"), "Price")
    )
    .SetResultTransformer(Transformers.AliasToBean<ProductRow>())
    .List<ProductRow>();

ProductRow各プロジェクションを追加するときに、 a のプロパティ名を指すエイリアスの使用に注意してください。

于 2010-02-14T08:10:59.633 に答える