FluentNHibernate error -- "Invalid object name"

Posted by goober on Stack Overflow See other posts from Stack Overflow or by goober
Published on 2010-05-16T15:03:34Z Indexed on 2010/05/16 15:10 UTC
Read the original article Hit count: 201

I'm attempting to do the most simple of mappings with FluentNHibernate & Sql2005. Basically, I have a database table called "sv_Categories". I'd like to add a category, setting the ID automatically, and adding the userid and title supplied.

Database table layout:

  • CategoryID -- int -- not-null, primary key, auto-incrementing
  • UserID -- uniqueidentifier -- not null
  • Title -- varchar(50) -- not null

Simple.

My SessionFactory code (which works, as far as I can tell):
            _SessionFactory = Fluently.Configure().Database(
                MsSqlConfiguration.MsSql2005
                    .ConnectionString(c => c.FromConnectionStringWithKey("SVTest")))
                    .Mappings(x => x.FluentMappings.AddFromAssemblyOf<CategoryMap>())
                    .BuildSessionFactory();

My ClassMap code:

public class CategoryMap : ClassMap<Category>
{
    public CategoryMap()
    { 
        Id(x => x.ID).Column("CategoryID").Unique();
        Map(x => x.Title).Column("Title").Not.Nullable();
        Map(x => x.UserID).Column("UserID").Not.Nullable();
    }
}

My Class code:

public class Category
{
    public virtual int ID { get; private set; }
    public virtual string Title { get; set; }
    public virtual Guid UserID { get; set; }

    public Category()
    { 
        // do nothing 
    }
}

And the page where I save the object:

    public void Add(Category catToAdd)
    {
        using (ISession session = SessionProvider.GetSession())
        {
            using (ITransaction Transaction = session.BeginTransaction())
            {
                session.Save(catToAdd);
                Transaction.Commit();
            }
        }
    }

I receive the error

Invalid object name 'Category'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'Category'.

I think it might be that I haven't told the CategoryMap class to use the "sv_Categories" table, but I'm not sure how to do that.

Any help would be appreciated. Thanks!

© Stack Overflow or respective owner

Related posts about fluent-nhibernate

Related posts about nhibernate