开发者

Nhibernate - query results to asp.net datagrid

 ISession s = Dal.Session;

        string queryString = @"select t.SellDate as SellDate, t.DocumentNumber as DocNo, t.PriceGross as Gross,
                                t.PaymentDate as PaymentDate, ts.SettlementValue as SettlementValue, ds.{Path} + '\' + ds.Name as FilePath
                               from TransactionSettlement ts, Transaction t, DocScanned ds
                                where ts.TransactionId = t.Id and t.DocID = ds.DocID and ts.PaymentId = :paymentID";

 query.SetInt32("paymentID", paymentID);
 IQuery query = s.CreateQuery(queryString);
 IList re开发者_如何学运维sultList = query.List();

How to bind nhibernate query results to asp.net datagrid?


Have you tried using LINQ to nHibernate to return an IEnumerable or IQueryable?

http://ayende.com/Blog/archive/2009/07/26/nhibernate-linq-1.0-released.aspx

http://www.hookedonlinq.com/LINQToNHibernate.ashx


So the error you're seeing is because your resultList is a list of object arrays (object[]) instead of actual objects.

What you could do to get the data into the shape that you want is to write a Linq (Linq to objects, not linq to nhibernate), it'll probably look something along these lines:

var newResultList = from r in resultList 
                    select new {
                        SellDate = r[0],
                        DocNo = r[1],
                        Gross = r[2],
                        PaymentDate = r[3],
                        SettlementValue = r[4],
                        FilePath = r[5]
                    };

Then you'll have an object you can more easily databind to. There's probably a way to databind each row to an array, I just haven't found an examples of how to do that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜