Mam troszkę wolnego czasu i chciałem chociaż w podstawowym stopniu ogarnąć NHibernate ale pojawił się problem z konfiguracją za pomocą fluent api. Zrobiłem wszystko jak w linku:
https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Getting-started
Aplikaca konsolową netcoreapp2.1
, VS 2017. Podczas uruchamiania aplikacji dostaję błąd:
NHibernate.HibernateException
HResult=0x80131500
Message=Could not create the driver from NHibernate.Driver.SqlClientDriver, NHibernate, Version=5.1.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4.
Source=NHibernate
StackTrace:
at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary2 settings) at NHibernate.Connection.ConnectionProvider.Configure(IDictionary
2 settings)
at NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider(IDictionary2 settings) at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Action
1 scriptAction, Boolean execute, Boolean justDrop, TextWriter exportOutput)
at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Boolean useStdOut, Boolean execute, Boolean justDrop)
at NHibernateTutorial.Program.<>c.<CreateSessionFactory>b__3_0(Configuration cfg) in C:\Projects\NHibernateTutorial\NHibernateTutorial\Program.cs:line 83
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
Inner Exception 1:
TargetInvocationException: Exception has been thrown by the target of an invocation.
Inner Exception 2:
HibernateException: The DbCommand and DbConnection implementation in the assembly System.Data.SqlClient could not be found. Ensure that the assembly System.Data.SqlClient is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use <qualifyAssembly/> element in the application configuration file to specify the full name of the assembly.
Z EF Core nie ma żadnych problemów, jeśli baza nie istnieje to ef ją sobie tworzy. NHibernate nie wspiera core 2.1 czy ja coś źle skonfigurowałem? Podczas debugowania błąd występuje w linijce new SchemaExport(cfg).Execute(true, true, false);
private static ISessionFactory CreateSessionFactory()
{
const string connectionString = "Data source=(LocalDb)\\MSSQLLocalDB;Database=NHibernateTest;Integrated Security=True";
var sqlConfiguration = MsSqlConfiguration.MsSql2012
.ConnectionString(connectionString)
.ShowSql();
Action<Configuration> config = cfg =>
new SchemaExport(cfg)
.Execute(true, true, false);
return Fluently.Configure()
.Database(sqlConfiguration)
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Program>())
.ExposeConfiguration(config)
.BuildSessionFactory();
}