NHibernate: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
(One intermediate revision by the same user not shown) | |||
Line 95: | Line 95: | ||
* [https://www.dotnetjalps.com/2014/07/fluent-nhibernate-asp-net-mvc-crud.html ASP.NET MVC & Fluent Nhibernate] | * [https://www.dotnetjalps.com/2014/07/fluent-nhibernate-asp-net-mvc-crud.html ASP.NET MVC & Fluent Nhibernate] | ||
* [https://ivanderevianko.com/2015/04/vnext-use-postgresql-fluent-nhibernate-from-asp-net-5-dnx-on-ubuntu Fluent NHibernate with PostgreSQL] | * [https://ivanderevianko.com/2015/04/vnext-use-postgresql-fluent-nhibernate-from-asp-net-5-dnx-on-ubuntu Fluent NHibernate with PostgreSQL] | ||
* [https://github.com/auth0-blog/dependency-injection-dotnet-core Dependency Injection in .NET Core] | |||
| valign="top" | | |||
* [https://auth0.com/blog/dependency-injection-in-dotnet-core Understanding Dependency Injection in .NET Core] | |||
* [https://codeburst.io/jwt-auth-in-asp-net-core-148fb72bed03 JWT Auth in ASP.NET Core] | |||
|} | |||
---- | |||
{| | |||
| valign="top" | | |||
| valign="top" | | |||
|} | |} |
Latest revision as of 00:52, 30 December 2020
App Settings
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"SqlServer": "Data Source=(localdb)\\MSSQLLocalDB;Database=hibernate;Integrated Security=True",
"Oracle": "Data Source=iis0.dev.shahed.biz:1521/xe;User Id=shahed_boot_dev;Password=shahed_boot_dev",
"MySQL": "Server=db00.dev.shahed.biz;Port=3306;Database=shahed_boot_dev;User Id=shahed_boot_dev;Password=shahed_boot_dev",
"PostgreSQL": "Server=db00.dev.shahed.biz;Port=5432;Database=shahed_boot_dev;User Id=shahed_boot_dev;Password=shahed_boot_dev"
}
}
NHibernate Config
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.driver_class">NHibernate.Driver.OracleManagedDataClientDriver</property>
<property name="connection.connection_string">Data Source=iis0.dev.shahed.biz:1521/xe;User Id=shahed_boot_dev;Password=shahed_boot_dev</property>
<property name="show_sql">true</property>
<property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
</session-factory>
</hibernate-configuration>
NHibernate Helper
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
using NHibernate.Tool.hbm2ddl;
using ChorkeAcademiaPersis.Entity;
using Microsoft.Extensions.Configuration;
using NHibernate.Cfg;
namespace ChorkeAcademiaPersis.Utility
{
public class NHibernateHelper
{
public static ISession OpenSession()
{
ISessionFactory sessionFactory = Fluently.Configure()
.Database(MySQLConfiguration.Standard.ConnectionString(Startup.StaticConfig.GetConnectionString("MySQL")).ShowSql())
//.Database(MsSqlConfiguration.MsSql2012.ConnectionString(Startup.StaticConfig.GetConnectionString("SqlServer")).ShowSql())
//.Database(PostgreSQLConfiguration.Standard.ConnectionString(Startup.StaticConfig.GetConnectionString("PostgreSQL")).ShowSql())
//.Database(OracleDataClientConfiguration.Oracle10.ConnectionString(Startup.StaticConfig.GetConnectionString("Oracle")).ShowSql())
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Employee>())
.ExposeConfiguration(ConfigModifier)
.BuildSessionFactory();
return sessionFactory.OpenSession();
}
private static void ConfigModifier(Configuration config)
{
//config.SetProperty(Environment.ConnectionDriver, "NHibernate.Driver.OracleManagedDataClientDriver");
//config.SetProperty(Environment.QuerySubstitutions, "true 1, false 0, yes 'Y', no 'N'");
//config.SetProperty(Environment.CurrentSessionContextClass, "thread_static");
var schemaExport = new SchemaExport(config);
schemaExport.Create(false, false);
}
}
}