指定的表不存在

时间:2011-06-15 02:40:16

标签: fluent-nhibernate

我尝试使用流利的nhibernate,但是我的nunit测试失败并出现错误

CookBook.Tests.FluentCategoryTests.CanCorrectlyMapCategory:
System.Data.SqlServerCe.SqlCeException : The specified table does not exist. [ Category ]

这是我的分类对象

public class Category
{
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
}

这是测试

[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 CanCorrectlyMapCategory()
    {
        using (ISession session = _sessionFactory.OpenSession())
        {
            new PersistenceSpecification<Category>(session)
            .CheckProperty(c => c.Id, 1)
            .CheckProperty(c => c.Name, "Dessert")
            .VerifyTheMappings();
        }
    }
}

那么我做错了什么?

1 个答案:

答案 0 :(得分:1)

回答你评论中的问题:

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();