Problem z konfiguracją NHibernate z LocalDb

0

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(IDictionary2 settings)
at NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider(IDictionary2 settings) at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Action1 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();
}
2

Doinstaluj paczkę System.Data.SqlClient.

0

Ok, zadziałało ale teraz jest problem z logowaniem. Nie powinno automatycznie mnie zalogować używając danych konta systemowego? Integrated Security=True zmieniałem też na SSPI i to samo.

NHibernate.HibernateException
HResult=0x80131500
Message=Cannot open database "NHibernateTest" requested by the login. The login failed.
Login failed for user 'AENYATIA-PC\Aenyatia'.
Source=NHibernate
StackTrace:
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:
SqlException: Cannot open database "NHibernateTest" requested by the login. The login failed.
Login failed for user 'AENYATIA-PC\Aenyatia'.

Utworzyłem pustą bazę danych za pomocą VS Server Explorer i w connectionString dodałem AttachDbFilename=path
Teraz po uruchomieniu tworzą się tabelę w podpiętej bazie danych i wszystko działa.
Czy da się ustawić, żeby plik bazy danych sam się tworzył przy pierwszym uruchomieniu? Czy w każdym projekcie będę musiał tworzyć ręcznie pustą db za pomocą VS i wskazywać jej ścieżkę w connectionString?

1 użytkowników online, w tym zalogowanych: 0, gości: 1