NHibernate 和 ASP.NET 绑定到的 IList?

发布于 2024-10-02 15:23:42 字数 348 浏览 2 评论 0原文

我最近开始使用 Nhibernate,我对它非常满意,直到我需要绑定到 ASP.NET 控件。我在将 gridview 绑定到产品集合(IList)时遇到了重大问题。最后,我被迫纠正一个小例程,将 IList 转换为 DataTable。一旦它进入数据表,它就可以完美地工作。

现在是将标准下拉框绑定到产品集合(IList)的 1 个字段的时候了,但似乎我又遇到了问题。

所以这让我得出结论:我一定做错了什么?

我不敢相信不可能将 ASP.NET 控件绑定到从 NHibernate 返回的类(在我的例子中为产品)的集合 (IList)。

我真的很感激任何人对这种情况的反馈......我很茫然

谢谢你

I have recently started to use Nhibernate and i am quite happy with it until i needed to BIND to ASP.NET controls. I was having major issues binding a gridview to a collection of Products (IList). In the end i was forced to right a small routine to convert my IList to a DataTable. Once it was in datatable it worked flawlessy.

Now has come the time to bind a standard Dropdownbox to 1 field of a collection (IList) of Products but it appears i am having issues again.

So this has brought me to the conclusion that i must be doing something wrong?

I can't believe that it isn't possible to BIND ASP.NET controls to a collection (IList) of a class (in my case products) that is returned from NHibernate.

I would really appreciate any feedback anyone has on the situation... I am at a loss

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瀞厅☆埖开 2024-10-09 15:23:42

问题不在于你不能绑定,因为你可以。通常,当您在错误的时间绑定时,就会出现此类问题。

NHibernate 支持惰性。因此,如果您的查询是惰性的,并且返回对象的属性是惰性的,那么在引用项目和属性之前,不会从数据库中提取值。如果将它们绑定到 UI 中的控件,则在渲染页面之前不会提取这些值。

此时,您很可能已经关闭数据库连接

简单的解决方案是确保您绑定的数据不是延迟加载。

The problem is not that you can't bind, because you can. Generally issues like this come about when you're binding at the wrong time.

NHibernate supports laziness. So if your query is lazy, and properties on the returned objects are lazy, then the values won't be pulled from the database until the items and properties are referenced. If you bind these to controls in the UI, then the values won't be extracted until the page gets rendered.

At this point there is a good chance that you have already closed your database connection.

The simple solution is to make sure that the data you're binding to is not lazily loaded.

梦屿孤独相伴 2024-10-09 15:23:42

创建 ListBindingList 对象,并将 IList 对象从查询传递到构造函数中。如果 IList 对象不是通用列表,您可以使用 LINQ、ilistObject.Cast().ToList()

Create a List<T> or BindingList<T> object and pass the IList object from the query into the constructor. If the IList object is not a generic list, you can use LINQ, ilistObject.Cast<T>().ToList().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文