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

[WIP] NH-3807 Support for .NET Core 1.0 #504

Closed
wants to merge 53 commits into from

Conversation

ngbrown
Copy link
Contributor

@ngbrown ngbrown commented Aug 21, 2016

Link to the NH-3807 issue in Jira

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_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.

@hazzik hazzik added this to the 6.0.0 milestone Aug 21, 2016
@danielcweber
Copy link

danielcweber commented Aug 23, 2016

Great work. Would it make sense to factor NHibernate's functionality into smaller components (assemblies) so that some components may run on netstandard while others would only run on a full framework?

@ngbrown
Copy link
Contributor Author

ngbrown commented Aug 24, 2016

The most obvious part that could be sliced off is the NHibernate.Tool.hbm2ddl namespace and the associated NHibernate.Dialect.Schema namespaces. These areas currently do not work as written with .Net Core and it's questionable if they ever will. See dotnet/corefx#3423 and dotnet/corefx#5024.

Most likely an alternative approach will have to be made where the NHibernate hbm2ddl functionality, that is schema synchronization, knows how to talk to the database meta-tables instead of relying on the driver to do it. This may be easier if it is already refactored into a separate library.

For example, Entity Framework Core talks to each kind of database through SQL commands to get the database metadata: /Microsoft.EntityFrameworkCore.Sqlite.Design/Internal/SqliteDatabaseModelFactory.cs.

Another part that is a possibility, is how the various database drivers are demand loaded through reflection. I don't know if they will all be consistent over to the .Net Core world and it might make sense to have each type of database support refactored out into separate libraries. The database support libraries could then link for real with their respective drivers and pull them down from NuGet as dependencies.

I hope you can join in and see what can be done.

@mattzink
Copy link

These areas currently do not work as written with .Net Core and it's questionable if they ever will. See dotnet/corefx#3423 and dotnet/corefx#5024.

Microsoft has recently stated that they are adding back the full data API of .NET Framework for .NET Standard 2.0, so these scenarios will certainly be supported again in the first half of 2017.

@ngbrown
Copy link
Contributor Author

ngbrown commented Sep 5, 2016

@mattzink Yes, they seem to be adding serialization back in, but that is the least of NHibernates problems. There has been no commitment to bringing DbConnection.GetSchema() and DataTable back. See dotnet/corefx#5024 and dotnet/corefx#1039.

I think the path forward is to get at least some of the tests running without requiring dynamic schema generation, and then start working on pulling each database schema in implementation specific ways instead of relying on ADO.Net.

Any thoughts on this? Would any database's schema and hbm2ddl methods benefit by being more database specific rather than relying on ADO.Net providers?

@jeffreyabecker
Copy link

Right now it looks like many of the dialects rely on AbstractDatabaseSchema to do most of the work of getting the schema. Would it be possible to have that class expose utility methods for querying INFORMATION_SCHEMA?

@ngbrown
Copy link
Contributor Author

ngbrown commented Sep 29, 2016

Microsoft has announced their direction on .NET Standard 2.0. Basically, they are adding back BinaryFormatter for serialization, but appear to be totally removing System.Data. NHibernate worked with serialization, but didn't really depend on it for any major functionality. It does however heavily depend on System.Data.

Entity Framework has pulled everything it needs out of System.Data and put it into Microsoft.Data. See dotnet/efcore#2665. [Edit: This is talking about namespaces, and seems to have been before parts System.Data.Common was added back to netstandard].

What is NHibernate's position for the future going to be? I've heard from companies I work with that they liked NHibernate in the past, but are moving to Entity Framework because it runs on .NET Core. How is NHibernate going to stay relevant?

@gliljas
Copy link
Member

gliljas commented Sep 29, 2016

By doing the same, I would say.

/G

2016-09-29 16:08 GMT+02:00 Nathan Brown notifications@github.com:

Microsoft has announced their direction on .NET Standard 2.0
https://blogs.msdn.microsoft.com/dotnet/2016/09/26/introducing-net-standard/.
Basically, they are adding back BinaryFormatter for serialization, but
appear to be totally removing System.Data. NHibernate worked with
serialization, but didn't really depend on it for any major functionality.
It does however heavily depend on System.Data.

Entity Framework has pulled everything it needs out of System.Data and
put it into Microsoft.Data. See dotnet/efcore#2665
dotnet/efcore#2665.

What is NHibernate's position for the future going to be? I've heard from
companies I work with that they liked NHibernate in the past, but are
moving to Entity Framework because it runs on .NET Core. How is NHibernate
going to stay relevant?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#504 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AARt9jTIBgql5x5cuxvNwDTHUJbaFc9sks5qu8ZRgaJpZM4JpaPY
.

@hazzik
Copy link
Member

hazzik commented Oct 3, 2016

can we resue Microsoft.Data?

@ngbrown
Copy link
Contributor Author

ngbrown commented Oct 3, 2016

@hazzik It's not so much as there is a library to re-use, but that Entity Framework itself implements whatever it needs to that was missing.

@hazzik
Copy link
Member

hazzik commented Oct 26, 2016

Do I understand correctly that with .NETStandard 2.0 only the minimal work will be required?

@ssinno28
Copy link

I'm having an issue with Antlr3.Runtime being compatible with .Net Standard 1.6.. how do you get it compile? Did you just include "dnx451"? I want to get it to work cross platform, do we need to upgrade to antlr4.runtime (which seems to be compatible with aspnet core)?

@ngbrown
Copy link
Contributor Author

ngbrown commented Nov 23, 2016

@ssinno28 I used Antlr3.Runtime. I made my own build and the NuGet package feed is available at https://ci.appveyor.com/nuget/antlrcs-xwvu6kkh1nnu. I used version 3.5.0.3-dev-201608090747.

It's from my own branch https://github.com/ngbrown/antlrcs/tree/fix-version which is mostly just fixes to the appveyor.yml file.

@RockNHawk
Copy link

Any follow-up?

@ssinno28
Copy link

Adding the nuget package URL worked.. Since VS 2017 RC came out I've been having issues with the new way they are using the .csproj... For whatever reason it is refusing to build.. going to wait until the nhibernate team decides to convert it to .Net core which is when .Net standard 2.0 is getting released..

…ly replacing NET_2_0's SecurityPermissionAttribute
…String.

FormatterConverter has been removed from CoreClr.
So we don't have to #if #endif around every single usage.

Adds minimal implementation of:
DesignerCategoryAttribute
IntrospectionExtensions
NonSerializedAttribute
SerializableAttribute

RuntimeReflectionExtensions
IntrospectionExtensions

InvalidExpressionException
ApplicationException has been removed from CoreClr.
Array.ConvertAll has been removed from CoreClr.
@hazzik
Copy link
Member

hazzik commented Mar 16, 2017

@ngbrown I'm going to rebase your changes on top of master (it means drop some of the commits) and migrate to VS2017 format.

@hazzik
Copy link
Member

hazzik commented Mar 17, 2017

Rebased on top of master & converted to VS2017 (.NET SDK 1.0.1)

@hazzik
Copy link
Member

hazzik commented May 1, 2017

Closing this for now. Thanks for the great work, @ngbrown.

@hazzik hazzik closed this May 1, 2017
@RockNHawk
Copy link

@hazzik @ngbrown
It means NHibernate now supports .NET Core ?

@hazzik
Copy link
Member

hazzik commented May 1, 2017

@DarkLx no.

This PR was targeting .NET Core 1.0. NHibernate is going to support .NET Core 2.0 and the work required is hardly intersected with this PR (most of this is not required).

@RockNHawk
Copy link

@hazzik
Okay,Thanks for the great work !
Should we use this .NET Core 1.0 version NHibernate on production ?

@hazzik
Copy link
Member

hazzik commented May 1, 2017 via email

@RockNHawk
Copy link

RockNHawk commented May 1, 2017

@hazzik
Hah Hah Hah, OK, I know~

@ngbrown ngbrown deleted the NH-3807 branch May 3, 2017 04:38
@hazzik hazzik removed this from the 6.0 milestone Nov 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants