Using a custom IList obtained through NHibernate

Posted by Abu Dhabi on Stack Overflow See other posts from Stack Overflow or by Abu Dhabi
Published on 2010-04-17T23:44:29Z Indexed on 2010/04/17 23:53 UTC
Read the original article Hit count: 398

Filed under:
|
|

Hi.I'm trying to write a web page in .NET, using C# and NHibernate 2.1.

The pertinent code looks like this:

var whatevervar = session.CreateSQLQuery("select thread_topic, post_time, user_display_name, user_signature, user_avatar, post_topic, post_body from THREAD, [USER], POST, THREADPOST where THREADPOST.thread_id=" + id + " and THREADPOST.thread_id=THREAD.thread_id and [USER].user_id=POST.user_id and POST.post_id=THREADPOST.post_id ORDER BY post_time;").List();

(I have tried to use joins in HQL, but then fell back on this query, due to HQL's unreadability.) The problem is that I'm getting a result that is incompatible with a repeater. When I try this:

posts.DataSource = whatevervar.;
posts.DataBind();

...I get this:

DataBinding: 'System.Object[]' does not contain a property with the name 'user_avatar'.

In an earlier project, I used LINQ to SQL for this same purpose, and it looked like so:

var whatevervar = from threads in context.THREADs
                          join threadposts in context.THREADPOSTs
                            on threads.thread_id equals threadposts.thread_id
                          join posts1 in context.POSTs
                            on threadposts.post_id equals posts1.post_id
                          join users in context.USERs
                            on posts1.user_id equals users.user_id
                          orderby posts1.post_time
                          where threads.thread_id == int.Parse(id)
                          select new
                          {
                              threads.thread_topic,
                              posts1.post_time,
                              users.user_display_name,
                              users.user_signature,
                              users.user_avatar,
                              posts1.post_body,
                              posts1.post_topic
                          };

That worked, and now I want to do the same with NHibernate. Unfortunately, I don't know how to make the repeater recognize the fields of the result of the query.

Thanks in advance!

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about .NET