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

  • SEARCH
  • Home
  • 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 1065883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T19:55:20+00:00 2026-05-16T19:55:20+00:00

I’m trying to map myexisting database by Fluent NHibernate I get error: The element

  • 0

I’m trying to map myexisting database by Fluent NHibernate I get error:

The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element 'many-to-one' in namespace 'urn:nhibernate-mapping-2.2'. List of possible elements expected: 'meta, subselect, cache, synchronize, comment, tuplizer, id, composite-id' in namespace 'urn:nhibernate-mapping-2.2'."}

I’m newbie in Fluent and I don’t know how to fix it ? (maybe it is because id is string ?)

Here is my model class:

namespace Server.Model
{
    public partial class User
    {
        string _name;

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        string _email;

        public string Email
        {
            get { return _email; }
            set { _email = value; }
        }
        TypeOfUser _typeOfUser;

        public TypeOfUser TypeOfUser
        {
            get { return _typeOfUser; }
            set { _typeOfUser = value; }
        }
        string _idUser;

        public string IdUser
        {
            get { return _idUser; }
            set { _idUser = value; }
        }

        public string Password { get; set; }

        public static void AddUserTest()
        {
            var sessionFactory = BuildSessionFactory();

            using (ISession session = sessionFactory.OpenSession())
            {

                using (ITransaction transaction = session.BeginTransaction())
                {

                    session.Save(new User()
                                     {
                                         _idUser = "adapol",
                                         _name = "Adam Mickiewicz",
                                         _email = "adamm@wp.pl",
                                         _typeOfUser = Model.TypeOfUser.NormalUser
                                     });
                }
            }
        }

        private static ISessionFactory BuildSessionFactory()
        {
            AutoPersistenceModel model = CreateMappings();

            return Fluently.Configure().Database(MsSqlConfiguration.MsSql2005
  .ConnectionString(c => c.FromConnectionStringWithKey("gwd"))).Mappings(m => m.AutoMappings.Add(model))
    .ExposeConfiguration((Configuration config) => new SchemaExport(config).Create(false, true)).BuildSessionFactory();

        }

        private static AutoPersistenceModel CreateMappings()
        {
            return AutoMap
                .Assembly(System.Reflection.Assembly.GetCallingAssembly())
                .Where(t => t.Namespace == "Server.Mappings");
        }


    }
}

I have only one classMap

namespace Server.Mappings
{
    public class UserMap : ClassMap<User>
    {
        public UserMap()
        {
            Table("Users");

            Id(x => x.IdUser,"IdUser");
            Map(x => x.Email);
            Map(x => x.Name);
            Map(x => x.Password);
            Map(x => x.TypeOfUser,"Type");
        }
    }
}

This is script to create my table( it already exists):

USE [GWD]
GO
/****** Object:  Table [dbo].[Users]    Script Date: 09/02/2010 23:08:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Users](
    [IDuser] [nvarchar](50) NOT NULL,
    [Type] [int] NOT NULL,
    [Name] [nvarchar](max) NOT NULL,
    [Email] [nvarchar](50) NOT NULL,
    [Password] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED 
(
    [IDuser] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
  • 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-16T19:55:21+00:00Added an answer on May 16, 2026 at 7:55 pm

    Instead of relying on automappings:

    private static ISessionFactory BuildSessionFactory()
            {
                AutoPersistenceModel model = CreateMappings();
    
                return Fluently.Configure().Database(MsSqlConfiguration.MsSql2005
      .ConnectionString(c => c.FromConnectionStringWithKey("gwd"))).Mappings(m => m.AutoMappings.Add(model))
        .ExposeConfiguration((Configuration config) => new SchemaExport(config).Create(false, true)).BuildSessionFactory();
    
            }
    

    Try this:

    private static ISessionFactory BuildSessionFactory()
    {
        return Fluently
            .Configure()
            .Database(
                MsSqlConfiguration
                    .MsSql2005
                    .ConnectionString(c => c.FromConnectionStringWithKey("gwd"))
             )
             .Mappings(m => m.FluentMappings.AddFromAssemblyOf<UserMap>())
             .ExposeConfiguration(config => new SchemaExport(config).Create(false, true))
             .BuildSessionFactory();
    }
    

    Also you might need to make the User properties virtual.


    And here’s a full working example using SQLite that I’ve put to illustrate sample configuration:

    public class User
    {
        public virtual string IdUser { get; set; }
        public virtual string Name { get; set; }
        public virtual string Email { get; set; }
        public virtual string Password { get; set; }
    }
    
    public class UserMap : ClassMap<User>
    {
        public UserMap()
        {
            Table("Users");
            Id(x => x.IdUser);
            Map(x => x.Email);
            Map(x => x.Name);
            Map(x => x.Password);
        }
    }
    
    
    class Program
    {
        static void Main(string[] args)
        {
            if (File.Exists("data.db3"))
            {
                File.Delete("data.db3");
            }
    
            using (var factory = CreateSessionFactory())
            {
                using (var connection = factory.OpenSession().Connection)
                {
                    ExecuteQuery("create table Users(IdUser string primary key, Name string, Email string, Password string)", connection);
                }
    
                using (var session = factory.OpenSession())
                using (var tx = session.BeginTransaction())
                {
                    session.Save(new User()
                    {
                        IdUser = "adapol",
                        Name = "Adam Mickiewicz",
                        Email = "adamm@wp.pl",
                    });
                    tx.Commit();
                }
            }
        }
    
        private static ISessionFactory CreateSessionFactory()
        {
            return Fluently.Configure()
                .Database(
                    SQLiteConfiguration.Standard.UsingFile("data.db3").ShowSql()
                )
                .Mappings(
                    m => m.FluentMappings.AddFromAssemblyOf<UserMap>()
                )
                .BuildSessionFactory();
        }
    
        static void ExecuteQuery(string sql, IDbConnection connection)
        {
            using (var command = connection.CreateCommand())
            {
                command.CommandText = sql;
                command.ExecuteNonQuery();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and

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.