English 中文(简体)
GridView doesn t cause NHibernate proxy to load relationships
原标题:

I m currently learning NHibernate and I would like to data-bind to Web controls (i.e. GridView).

In my current example I am using Fluent NHibernate to map two tables to their business objects (Project and ProjectStatus). I also have a "Project has a ProjectStatus" (many-to-one) relationship.

Structure of Project class:

Project.ID
Project.Name
Project.ProjectStatus.Name
Project.ProjectStatus.Description

When I bind a list of Project objects (with lazy="proxy") to a GridView, the GridView does not trigger the load of the referenced table. As a result the fields Name and Description of ProjectStatus are left out by the GridView control.

Is there a way of having true lazy loading in combination with a data-bound GridView?

Thanks in advance.

最佳回答

This should work without any problems. I suspect the problem is in the data binding itself not accessing the properties of a child object. How are you binding to the ProjectStatus properties? As far as I know, you can t directly bind to child objects. You have to set values in an OnRowDataBound event handler or by using Eval.

I would first create an OnRowDataBound handler and break on a DataRow. Examine e.Row.DataItem in the immediate window to verify that the child object is being loaded. If it is, then the problem lies with the binding.

问题回答

Are you storing your ISession in the request context and flushing it at the end of the request? If not, you should start a new session in the begin_ request method of the global.asax.cs, store it in request context, then grab it back in the end_request method, and flush it.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签