문제

I have the following code to create an in-memory SQLite DB for testing:

        Configuration config = null;
        FluentConfiguration fluentConfiguration = Fluently.Configure().Database(SQLiteConfiguration.Standard.InMemory().ShowSql()
            ).Mappings(m =>
                {
                    m.FluentMappings.AddFromAssemblyOf<ReturnSourceMap>();
                    m.HbmMappings.AddFromAssemblyOf<ReturnSourceMap>();
                    m.FluentMappings.AddFromAssemblyOf<EchoTransaction>();
                }).ExposeConfiguration(c => config = c);

        ISessionFactory sessionFactory = fluentConfiguration.BuildSessionFactory();

        _session = sessionFactory.OpenSession();

        new SchemaExport(config).Execute(true, true, false, _session.Connection, Console.Out);

which seems to work fine for most things but unfortunately it is creating all the columns as not nullable.

For instance I have two classes:

InternalFund and ExternalFund. Both inherit from Fund and both persist to the same table.

ExternalFund has a column Manager_ID, InternalFund doesn't. Unfortunately this means that I can't persist an InternalFund as it throws a SQL Exception.

I don't need the referential integrity for my tests so would be happy if I could just make all columns nullable.

Does anyone know how to do this?

Thanks

Stu

도움이 되었습니까?

해결책 2

Oops, terribly sorry. It seems that the SQLite DB assumes nullability unless otherwise stated - unlike TSQL which requires it in the create statement.

In fact, I found hidden away in a sub-method that the particular property had a not null set on it in the mapping. Removing this sorted the problem.

Thanks for posting about conventions though, I'll have a look as I have another issue that they might sort.

Cheers

Stu

다른 팁

You should try using the FluentNhibernate feature of Conventions. If you check out this link you will see the first example is of setting nullability as a default.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top