Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 696905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:06:47+00:00 2026-05-14T03:06:47+00:00

My User table I want to map to aspnet_Users: <class name=User table=`User`> <id name=ID

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:06:48+00:00Added an answer on May 14, 2026 at 3:06 am

    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:

    class User
    {
         public virtual int ID { get; set; }
         public virtual Guid UserId { get; set; }
         public virtual string FullName { get; set; }
         public virtual string PhoneNumber { get; set; }   
    }
    
    class AspnetUser
    {
         public virtual Guid ID { get; set; }
         public virtual string UserName { get; set; }
    }
    

    mapping would be (using fluent.NHibernate):

      public class User_Map : ClassMap<User>
      {
          public User_Map()
          {
               Table("User");
               ID(x => x.ID).GeneratedBy.Native();
               References(x => x.UserId);
               Map(x => x.FullName);
               Map(x => x.PhoneNumber);
          }
      }
    
      public class AspnetUser_Map : ClassMap<AspnetUser>
      {
          public User_Map()
          {
               Table("aspnet_Users");
               ID(x => x.ID).GeneratedBy.Assigned();
               Map(x => x.UserName);
          }
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.