I am having a problem when databinding a gridview to an IList of results from nHibernate. When the first item in the list is not a proxy object, it works fine. But if it is a proxy object, I get this error:
Code:
TargetInvocationException: Property accessor 'Username' on object 'ThisProject.Domain.Model.Implementations.User' threw the following exception:'Object does not match target type.'
My code is pretty simple:
Code:
IList<User> users = _userRepository.GetUsersForSite(currentSite.Id);
gvUsers.DataSource = users;
gvUsers.DataBind();
My mapping file:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="ThisProject.Domain.Model.Implementations" assembly="ThisProject.Domain" default-access="field.camelcase-underscore" >
<class name="User" table="Users" dynamic-update="true">
<id name="Id" column="user_id" type="Int32">
<generator class="identity" />
</id>
<property name="Username" type="String" insert="false" update="false"/>
<property name="FirstName" column="name_first" insert="false" update="false" />
<property name="LastName" column="name_last" insert="false" update="false" />
<property name="MiddleName" column="name_middle" insert="false" update="false" />
<property name="Suffix" column="name_suffix" insert="false" update="false" />
<property name="PhoneNumber" column="phone" insert="false" update="false" />
<property name="FaxNumber" column="fax" insert="false" update="false" />
<property name="EmailAddress" column="email" insert="false" update="false" />
<property name="JobTitle" column="job_title" insert="false" update="false" />
<property name="IsActive" column="is_active" insert="false" update="false" />
<property name="DealerID" column="dlrcode" insert="false" update="false" />
<bag name="AccessibleSites" table="users_sites" cascade="none" lazy="true">
<key column="user_id" />
<many-to-many column="site_id" class="ThisProject.Domain.Model.Implementations.Site, ThisProject.Domain"/>
</bag>
</class>
</hibernate-mapping>