开发者

Telerik RadGrid Binding Assuming Wrong Object Type

开发者 https://www.devze.com 2023-01-28 21:20 出处:网络
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:

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>开发者_Go百科;

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.


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).

0

精彩评论

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