NHibernate Fluent C # Mapping Isuses

I create a table as:

CREATE TABLE [dbo].[Users](
Id int NOT NULL IDENTITY (1,1) PRIMARY KEY,
EmailAddress varchar(255),
FullName varchar(255),
Password varchar(255),
);

My model:

public class UserModel : Entity
{
    public virtual string EmailAddress { get; set; }
    public virtual string FullName { get; set; }
    public virtual string Password { get; set; }
}

My entity class:

public abstract class Entity
{
    public virtual int Id { get; set; }
}

My mapping class is simple, as shown below:

public class UserModelMap : ClassMap<UserModel>
{
    public UserModelMap()
    {
        Table("Users");
        Id(x => x.Id);
        Map(x => x.EmailAddress);
        Map(x => x.FullName);
        Map(x => x.Password);
    }
}

And I include all my classes that need to be mapped using the following configuration:

        private static void InitializeSessionFactory()
    {
        _sessionFactory = Fluently.Configure()
            .Database(MsSqlConfiguration.MsSql2008
             .ConnectionString(c => c.FromConnectionStringWithKey("DefalutConnection"))
            )
            .Mappings(m =>
                      m.FluentMappings
                          .AddFromAssemblyOf<Entity>())
            .ExposeConfiguration(cfg => new SchemaExport(cfg)
                                            .Create(true, true))
            .BuildSessionFactory();
    }

But when I query my database using the following code:

Session.Query<TEntity>();

Where TEntityis is my user model, I do not get any rows from the database.

I can't seem to figure out what the problem is.

+4
source share
1 answer

I would say that the problem is here:

.ExposeConfiguration(cfg 
   => new SchemaExport(cfg).Create(true, true)) // here

, NHibernate: , , . . , .

:

:

SchemaUpdate, . : http://geekswithblogs.net/dotnetnomad/archive/2010/02/22/138094.aspx

+1

All Articles