开发者

The specified table does not exist

开发者 https://www.devze.com 2023-03-12 20:11 出处:网络
I\'m try to use fluent nhibernate but my nunit test it failing with a The error CookBook.Tests.FluentCategoryTests.CanCorrectlyMapCategory:

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

精彩评论

暂无评论...
验证码 换一张
取 消