nhibernate / fluent-nhibernate

Fluent NHibernate!
BSD 3-Clause "New" or "Revised" License
1.66k stars 686 forks source link

Microsoft.Data.Sqlite with latest fluentnhibernate - update of tables not working #622

Closed PriyankaChandrabose closed 11 months ago

PriyankaChandrabose commented 1 year ago
_sessionFactory = Fluently.Configure()
  .Database(
    MsSqliteConfiguration.Standard
      .ConnectionString(c => c.Is($"data source={_dbFilePath};"))
      .Dialect<NHibernate.Extensions.Sqlite.SqliteDialect>()
      .Driver<NHibernate.Extensions.Sqlite.SqliteDriver>()
    )
  .Mappings(m => m.FluentMappings.AddFromAssemblyOf())
  .ExposeConfiguration(BuildSchema).BuildSessionFactory();

When schema update is being called, the following exception came with or with out actual schema update

ERROR NHibernate.Tool.hbm2ddl.SchemaUpdate - could not complete schema update
System.ArgumentException: More restrictions were provided than the collection 'Tables' supports.
at Microsoft.Data.Sqlite.SqliteConnection.GetSchema(String collectionName, String[] restrictionValues)
at NHibernate.Dialect.Schema.AbstractDataBaseSchema.GetTables(String catalog, String schemaPattern, String tableNamePattern, String[] types)
at NHibernate.Dialect.Schema.SQLiteDataBaseMetaData.GetTables(String catalog, String schemaPattern, String tableNamePattern, String[] types)
at NHibernate.Tool.hbm2ddl.DatabaseMetadata.GetTableMetadata(String name, String schema, String catalog, Boolean isQuoted)
at NHibernate.Cfg.Configuration.GenerateSchemaUpdateScript(Dialect dialect, IDatabaseMetadata databaseMetadata)
at NHibernate.Tool.hbm2ddl.SchemaUpdate.Execute(Action`1 scriptAction, Boolean doUpdate)
PriyankaChandrabose commented 1 year ago

Any update on this issue. The schema is not getting updated and throws the above exception

PriyankaChandrabose commented 1 year ago

how to connect nhibernate with Microsoft.Data.Sqlite without using extensions and make schema update work

hazzik commented 1 year ago

Thanks. I don't really know what is Hibernate.Extensions.Sqlite.SqliteDialect. I'll take a look at the issue later in the week.

PriyankaChandrabose commented 1 year ago

To use nhibernate with Microsoft.data.sqlite to support creation and updation of tables - what driver and dialect to be used ? any examples available ?

PriyankaChandrabose commented 1 year ago

Hi,

Found the exact point of the error GetSchema MethodCall GetTables

GetTables method of nhibernate is passing second argument and sqlconnection.cs class of Microsoft.Data.Sqlite is throing exception is 2nd argument is passed. Can some one help me with this

fredericDelaporte commented 11 months ago

So, it looks like Microsoft.Data.Sqlite simply does not support a feature required by NHibernate for schema-update. The easier way to solve this is to ask for the feature on Microsoft side, if you find where to ask. But it seems they do not intend implementing it due to how they document this lack of support.

DbConnection.GetSchema() isn't implemented. This API isn't well-defined, so we recommend retrieving database metadata directly using standard SQLite APIs like the sqlite_master table and the table_info PRAGMA.

For more information, see Metadata.

On that later link:

Microsoft.Data.Sqlite doesn't implement the GetSchema method on DbConnection. Instead, you can query directly for schema information using the sqlite_master table and PRAGMA statements like table_info and foreign_key_list.

So, your other option is to implement your own SQLiteDataBaseMetaData following the recommendations of the above documentation.