4

I create my table like:

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

My model is:

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 is:

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

My mapping class is simple as 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 the have to be mapped using this following configuraiton:

        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 my user model i get no rows back from the database.

I cant seem to work out what the issue is here.

1 Answer 1

1

I would say, that the problem is here:

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

Because, as NHibernate says: everything is OK, no issue, no exception. Just NO data. And you are recreating schema all the time, I would say.

Check this:

An extract from one of the answers:

You could use SchemaUpdate, which will update the schema instead. Here's a blog post about it: http://geekswithblogs.net/dotnetnomad/archive/2010/02/22/138094.aspx

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.