My User table I want to map to aspnet_Users:
<class name="User" table="`User`">
<id name="ID" column="ID" type="Int32" unsaved-value="0">
<generator class="native" />
</id>
<property name="UserId" column="UserId" type="Guid" not-null="true" />
<property name="FullName" column="FullName" type="String" not-null="true" />
<property name="PhoneNumber" column="PhoneNumber" type="String" not-null="false" />
</class>
My aspnet_Users table:
<class name="aspnet_Users" table="aspnet_Users">
<id name="ID" column="UserId" type="Guid" />
<property name="UserName" column="UserName" type="string" not-null="false" />
</class>
I tried adding one-to-one, one-to-many and many-to-one mappings. The closest I can get is with this error: Object of type ‘System.Guid’ cannot be converted to type ‘System.Int32’.
How do I create a 1 way mapping from User to aspnet_User via the UserId column in User?
I am only wanting to create a reference so I can extract read-only information, affect sorts, etc. I still need to leave UserId column in User set up like it is now. Maybe a virtual reference keying off of UserId? Is this even possible with Nhibernate?
Unfortunately it acts like it only wants to use ID from User to map to aspnet_Users. Changing the table User to have it’s primary key be UserId instead of ID is not an option at this point.
Any help would be greatly appreciated. Thanks in advance.
Aspnet_user table has a primary key of type Guid.
Your table User has a primary key of type Int32.
You can look at this as your user table has a reference (one to one) to aspnet_users table.
But if you look at the aspnet_users table as if it is a ‘basket of values’ to assign to a user (like if you’d have a type of user (admin, moderator, …), but that would be many-to-one refrence (many users have one of the type) you can map it like that.
So:
mapping would be (using fluent.NHibernate):