I have my own NHibernate XML type (converts POCO to XML on the fly), so I can save objects to the database.
This works with SQL Server 2014 without any problems. However, when I try to run our unit tests that use SQLite, I get a lot of errors because of this.
System.ArgumentException: Dialect does not support DbType.Xml Parameter name: typecode.
I am using a custom type similar to what was mentioned here: How to map XML type columns to a strongly typed property of an object with NHibernate?
Now I need to figure out how to make this type work with SQLite.
What I've done:
-When registering SQLiteConfiguration, I specify a custom Dialect that registers an XMl ColumnType:
Configuration config = null; var db = SQLiteConfiguration.Standard.ConnectionString(_connectionString).ShowSql().Dialect("InvestX.Data.nHibernate.DbContext.SQLiteDialectWithManifestTyping"); _sessionFactory = new DbSessionFactory(Fluently .Configure() .Database(db) .Mappings(m => m.FluentMappings.Conventions.AddFromAssemblyOf<EnumConvention>()) .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly())) .ExposeConfiguration(c => config = c) .BuildSessionFactory());
...
base.RegisterColumnType(System.Data.DbType.Xml, "Xml");
-Make sure that XmlType returns the SQL type of the SQL type
It works great on SQL Server 2012, but is struggling with SQLite.
Other thoughts I had success by manually adding an XML type column to my database using ALTER SCRIPT, and then changing my NHibernate binding to the binding as nvarchar (MAX). This works in all scenarios unless my system needs to create a new database from scratch. This is a temporary solution (that is, the most permanent solution), so I am not a big fan of it.
Any thoughts?
c # xml sqlite nhibernate fluent-nhibernate
Ryan ternier
source share