Telerik RadGrid 绑定假设错误的对象类型

发布于 2024-10-05 14:57:11 字数 811 浏览 0 评论 0原文

我们使用 RadGrid 控件从存储库中检索 User 对象,该存储库使用 NHibernate 来检索对象。我使用的对象数据源定义为:

<asp:ObjectDataSource ID="UsersData" runat="server" SelectMethod="GetAll" DataObjectTypeName="TestingApp.Lib.Domain.User" TypeName="TestingApp.Lib.Repositories.UserRepository">
</asp:ObjectDataSource>

GetAll 的方法签名如下:

public IEnumerable<User> GetAll();

对于 NHibernate,一些用户实际上是扩展 User 的 AdminUsers。看来存储库当前首先返回 AdminUser 对象,并且控件似乎假设其余对象将是 AdminUser 而不是 User。这会导致抛出以下异常:

“无法将类型为“TestingApp.Lib.Domain.User”的对象转换为类型为“TestingApp.Lib.Domain.AdminUser”。”

有没有办法强制控件假定数据绑定对象是 User 而不是 AdminUser?谢谢!


后续

看来以这种方式与NHibernate一起使用的RadGrid不兼容并且无法工作。我们决定推出我们自己的解决方案。

We are using the RadGrid control to retrieve User objects from a repository that uses NHibernate to retrieve the objects. I am using an object data source defined as:

<asp:ObjectDataSource ID="UsersData" runat="server" SelectMethod="GetAll" DataObjectTypeName="TestingApp.Lib.Domain.User" TypeName="TestingApp.Lib.Repositories.UserRepository">
</asp:ObjectDataSource>

The method signature for GetAll is as follows:

public IEnumerable<User> GetAll();

With NHibernate, some Users are actually AdminUsers which extends User. It seems the repository is currently returning an AdminUser object first, and the control seems to be assuming then that the rest of the objects will be AdminUser rather than User. This causes the following exception to be thrown:

"Unable to cast object of type 'TestingApp.Lib.Domain.User' to type 'TestingApp.Lib.Domain.AdminUser'."

Is there a way to force the control to assume that data bound objects are User rather than AdminUser? Thanks!


Follow-up

It appears that the RadGrid used with NHibernate in this way is not compatible and will not work. We have decided to roll our own solution instead.

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

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

发布评论

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

评论(1

幽蝶幻影 2024-10-12 14:57:11

发挥神奇属性 MasterTableView.RetrieveDataTypeFromFirstItem 看看这是否有帮助。我认为在您的情况下应该将其设置为 false,或者如果设置为 true,则集合中的第一项应该是 User 类型(前提是 AdminUser 扩展了 User 类)。

Play the magic property MasterTableView.RetrieveDataTypeFromFirstItem to see if this helps. I think it should be set to false in your case or if set to true, your first item in the collection should be of type User (provided that AdminUser extends the User class).

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