0
votes

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.

1
Which version of the .net framework are you using? - jvanrhyn
We are using .NET 3.5. Thanks - Shane N

1 Answers

0
votes

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