Skip to content

Instantly share code, notes, and snippets.

@ngbrown
Last active August 21, 2016 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngbrown/30701c11ec58d784d3deb4c95296b1f8 to your computer and use it in GitHub Desktop.
Save ngbrown/30701c11ec58d784d3deb4c95296b1f8 to your computer and use it in GitHub Desktop.
NHibernate 5.x Core

NHibernate vs. Entity Framework

Creating a Model EF 6.x EF Core 1.x NHibernate 4.x NHibernate 5.x Core
Basic modelling (classes, properties, etc.)
Conventions
Custom conventions Partial
Data annotations
Fluent API
Inheritance: Table per hierarchy (TPH)
Inheritance: Table per type (TPT)
Inheritance: Table per concrete class (TPC)
Shadow state properties
Alternate keys
Many-to-many: With join entity
Many-to-many: Without join entity
Key generation: Database
Key generation: Client
Complex/value types
Spatial data
Graphical visualization of model
Graphical drag/drop editor
Model format: Code
Model format: EDMX (XML)
Reverse engineer model from database: Command line
Reverse engineer model from database: VS wizard
Incremental update model from database
Querying Data EF 6.x EF Core 1.x NHibernate 4.x NHibernate 5.x Core
LINQ: Simple queries Stable Stable
LINQ: Moderate queries Stable Stabilizing
LINQ: Complex queries Stable In-Progress
LINQ: Queries using navigation properties Stable In-Progress
“Pretty” SQL generation Poor
Mixed client/server evaluation
Loading related data: Eager
Loading related data: Lazy
Loading related data: Explicit
Raw SQL queries: Model types
Raw SQL queries: Un-mapped types
Raw SQL queries: Composing with LINQ
Saving Data EF 6.x EF Core 1.x NHibernate 4.x NHibernate 5.x Core
SaveChanges
Change tracking: Snapshot
Change tracking: Notification
Accessing tracked state Partial
Optimistic concurrency
Transactions
Batching of statements
Stored procedure
Detached graph support (N-Tier): Low level APIs Poor
Detached graph support (N-Tier): End-to-end Poor
Other Features EF 6.x EF Core 1.x NHibernate 4.x NHibernate 5.x Core
Migrations
Database creation/deletion APIs
Seed data
Connection resiliency
Lifecycle hooks (events, command interception, ...)
Database Providers EF 6.x EF Core 1.x NHibernate 4.x NHibernate 5.x Core
SQL Server
MySQL Paid only
PostgreSQL
Oracle Paid only
SQLite
SQL Compact
DB2
InMemory (for testing)
Azure Table Storage Prototype
Redis Prototype
Application Models EF 6.x EF Core 1.x NHibernate 4.x NHibernate 5.x Core
WinForms
WPF
Console
ASP.NET
ASP.NET Core
Xamarin Coming soon
UWP

This is currently a work in progress. It does compile and I have ran simple programs against it.

A majority of the changes were done to the mainline .NET version so all the mainline tests could be used during development. There are no tests ported to .NET Core yet, and this may be difficult without the dynamic schema support.

By necessity, it includes #241/NH-3431 - Replace System.Data with System.Data.Common and NH-3853 - Switch binary-serialization to an implementation that is supported by CoreClr.

There are a number of compromises that have to take place on .NET Core, chief among them is that there is no GetSchemaTable(). Without this, none of the dynamic schema generation or updates works. The tests, when implemented, will need a static schema checked into the repository for database restoration.

I think that NHibernate has a number of great features above what Entity Framework is providing and this prevents the choice of .NET Core as being the deciding factor against NHibernate.

Please try this branch out and work to help make it a reality.

Conditional Compilation Symbols

(source for table)

The following conditional compilation symbols (vertical) are currently defined for each of the build configurations (horizontal):

Symbol NET40 NET45 .NET Core
FEATURE_ADONET_SQLCOMMANDSET 🚫
FEATURE_APPDOMAIN 🚫
FEATURE_ASSEMBLYBUILDER_SAVE 🚫
FEATURE_BINDINGLIST 🚫
FEATURE_CODEDOM 🚫
FEATURE_DATA_CLOSE 🚫
FEATURE_DATA_GETCOLUMNSCHEMA 🚫 🚫
FEATURE_DATA_GETSCHEMATABLE 🚫
FEATURE_DBPROVIDERFACTORIES 🚫
FEATURE_INTERNALIZE_IESI 🚫 🚫
FEATURE_LEGACY_REFLECTION_API 🚫 🚫
FEATURE_NETCORE_ICLONEABLE_API 🚫 🚫
FEATURE_NETCORE_REFLECTION_API 🚫 🚫
FEATURE_ODBC_OLEDB 🚫
FEATURE_REFLECTEDTYPE 🚫
FEATURE_REMOTING 🚫
FEATURE_SECURITY_PERMISSIONS 🚫
FEATURE_SERIALIZATION 🚫
FEATURE_STRING_INTERN 🚫
FEATURE_SYSTEM_CONFIGURATION 🚫
FEATURE_SYSTEM_SERVICEMODEL 🚫
FEATURE_SYSTEM_TRANSACTIONS 🚫
FEATURE_WEB_SESSION_CONTEXT 🚫
FEATURE_XML_SCHEMAS 🚫
FEATURE_XML_VALIDATIONEVENTHANDLER 🚫
---
NET_4_0 🚫
NETSTANDARD 🚫 🚫
  • FEATURE_ADONET_SQLCOMMANDSET - enables support for accessing the internal SqlCommandSet for batching. Otherwise, no batching is enabled.
  • FEATURE_APPDOMAIN - enables support for features that make use of an AppDomain in the host.
  • FEATURE_ASSEMBLYBUILDER_SAVE - enabled support for saving the dynamically generated proxy assembly.
  • FEATURE_BINDINGLIST - enables support features that make use of System.ComponentModel.BindingList.
  • FEATURE_CODEDOM - enables support for CodeDom providers such as CSharpCodeProvider.
  • FEATURE_DATA_CLOSE - enables support for DbDataReader.Close(). .NET Core doesn't have this
  • FEATURE_DATA_GETCOLUMNSCHEMA - .NET Core has IDbColumnSchemaGenerator.GetDbColumnSchema on the DbDataReader implementations.
  • FEATURE_DATA_GETSCHEMATABLE - DbConnection has GetSchema implementation and DbDataReader has GetSchemaTable. .NET Core has IDbColumnSchemaGenerator.GetDbColumnSchema on the DbDataReader implementations.
  • FEATURE_DBPROVIDERFACTORIES - Has DbProviderFactories with globally registered DB providers. Otherwise needs driver assembly with specific name.
  • FEATURE_INTERNALIZE_IESI - Since NHibernate 4.0, only LinkedHashSet has been used from Iesi.Collections. We can internalize this and not refer to an external assembly.
  • FEATURE_LEGACY_REFLECTION_API - provides a shim for .NET 4.0 that emulates the TypeInfo API available in .NET 4.5+ and .NET Core.
  • FEATURE_NETCORE_ICLONEABLE_API - provides shims for missing ICloneable interface
  • FEATURE_NETCORE_REFLECTION_API - provides shims to implement missing functionality in .NET Core that has no alternatives.
  • FEATURE_ODBC_OLEDB - enables support for features that make use of System.Data.Odbc or System.Data.OleDb.
  • FEATURE_REFLECTEDTYPE - Get more precise information from what type a MemberInfo was retreived. Used in MapByCode, but not available in .NET Core.
  • FEATURE_REMOTING - supports remoting on various types including inheriting from MarshalByRefObject. Both System.Runtime.Remoting and WCF System.ServiceModel.
  • FEATURE_SECURITY_PERMISSIONS - enables the use of CAS and Security[Critical|SafeCritical|Transparent].
  • FEATURE_SERIALIZATION - enables support for serialization of dynamic proxies and other types.
  • FEATURE_STRING_INTERN - enables support for string.Intern()
  • FEATURE_SYSTEM_CONFIGURATION - enables features that use System.Configuration and the ConfigurationManager.
  • FEATURE_SYSTEM_SERVICEMODEL enables features that use System.ServiceModel such as WCF and OperationContext.
  • FEATURE_SYSTEM_TRANSACTIONS - enables features that use System.Transactions.
  • FEATURE_WEB_SESSION_CONTEXT - enables WebSessionContext and relies on System.Web.HttpContext.
  • FEATURE_XML_SCHEMAS - enables features around XmlSchema including XmlSchemaSet
  • FEATURE_XML_VALIDATIONEVENTHANDLER - enables handling ValidationEventHandler events.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment