I'm try to use fluent nhibernate but my nunit test it failing with a The error
CookBook.Tests.FluentCategoryTests.CanCorrectlyMapCategory:
System.Data.SqlServerCe.SqlCeException : The specified table does not exist. [ Category ]
this is my Category object
public class Category
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
}
and here is the test
[TestFixture]
class FluentCategoryTests
{
private ISessionFactory _sessionFactory;
private RecipeConfiguration configuration = new RecipeConfiguration();
[TestFixtureSetUp]
public void TestSetup()
{
var cfg = new RecipeConfiguration();
_sessionFactory = Fluently.Configure()
.Database(MsSqlCeConfiguration.Standard.ShowSql().ConnectionString("Data Source=CookBook.sdf"))
.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Category>(cfg)))
.BuildSessionFactory();
}
[Test]
public void CanC开发者_如何转开发orrectlyMapCategory()
{
using (ISession session = _sessionFactory.OpenSession())
{
new PersistenceSpecification<Category>(session)
.CheckProperty(c => c.Id, 1)
.CheckProperty(c => c.Name, "Dessert")
.VerifyTheMappings();
}
}
}
So what am I doing wrong?
to answer the question in your comment:
using NHibernate.Tool.hbm2ddl;
...
var cfg = new RecipeConfiguration();
_sessionFactory = Fluently.Configure()
.Database(MsSqlCeConfiguration.Standard.ShowSql().ConnectionString("Data Source=CookBook.sdf"))
.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Category>(cfg)))
.ExposeConfiguration(config => new SchemaExport(config).Execute(false, true, false))
.BuildSessionFactory();
精彩评论