Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
PriyankaChandrabose opened this issue Oct 3, 2023 · 6 comments

Comments

@PriyankaChandrabose
Copy link

PriyankaChandrabose commented Oct 3, 2023

_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
Copy link
Author

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

@PriyankaChandrabose
Copy link
Author

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

@hazzik hazzik transferred this issue from nhibernate/nhibernate-core Oct 4, 2023
@hazzik
Copy link
Member

hazzik commented Oct 4, 2023

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
Copy link
Author

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
Copy link
Author

PriyankaChandrabose commented Oct 9, 2023

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants