From ca6b0bcd07a0ea14aed71a410fb83e67ef4696a1 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Thu, 22 Sep 2011 15:50:03 -0700 Subject: [PATCH] #18116, #18082: Fixing Version column mapping Work Items: 18116, 18082 --HG-- branch : 1.x --- .../Migration/Records/DataMigrationRecord.cs | 18 +++++++++++++++++- .../Providers/AbstractDataServicesProvider.cs | 8 ++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Orchard/Data/Migration/Records/DataMigrationRecord.cs b/src/Orchard/Data/Migration/Records/DataMigrationRecord.cs index 40c7ca372..66a43d68d 100644 --- a/src/Orchard/Data/Migration/Records/DataMigrationRecord.cs +++ b/src/Orchard/Data/Migration/Records/DataMigrationRecord.cs @@ -1,7 +1,23 @@ -namespace Orchard.Data.Migration.Records { +using FluentNHibernate.Mapping; + +namespace Orchard.Data.Migration.Records { public class DataMigrationRecord { public virtual int Id { get; set; } public virtual string DataMigrationClass { get; set; } public virtual int Version { get; set; } } + + /// + /// Since the "Version" colmuns is "AutoMapped" in FluentNHibernate, and the currently used version + /// doesn't understand IVersionConvention and IVersionConventionAcceptance, we need to provide a manual + /// mapping. + /// + public sealed class DataMigrationRecordMap : ClassMap { + public DataMigrationRecordMap() { + Table("Orchard_Framework_DataMigrationRecord"); + Id(x => x.Id); + Map(x => x.DataMigrationClass); + Map(x => x.Version); + } + } } \ No newline at end of file diff --git a/src/Orchard/Data/Providers/AbstractDataServicesProvider.cs b/src/Orchard/Data/Providers/AbstractDataServicesProvider.cs index 5030e523c..0dc8c98e7 100644 --- a/src/Orchard/Data/Providers/AbstractDataServicesProvider.cs +++ b/src/Orchard/Data/Providers/AbstractDataServicesProvider.cs @@ -9,6 +9,7 @@ using FluentNHibernate.Conventions.Helpers; using NHibernate.Cfg; using Orchard.ContentManagement.Records; using Orchard.Data.Conventions; +using Orchard.Data.Migration.Records; using Orchard.Environment.ShellBuilders.Models; namespace Orchard.Data.Providers { @@ -22,12 +23,15 @@ namespace Orchard.Data.Providers { return Fluently.Configure() .Database(database) - .Mappings(m => m.AutoMappings.Add(persistenceModel)) + .Mappings(m => { + m.AutoMappings.Add(persistenceModel); + m.FluentMappings.Add(typeof (DataMigrationRecordMap)); + }) .BuildConfiguration(); } public static AutoPersistenceModel CreatePersistenceModel(IEnumerable recordDescriptors) { - return AutoMap.Source(new TypeSource(recordDescriptors)) + return AutoMap.Source(new TypeSource(recordDescriptors.Where(x => x.Type != typeof(DataMigrationRecord)))) // Ensure that namespaces of types are never auto-imported, so that // identical type names from different namespaces can be mapped without ambiguity .Conventions.Setup(x => x.Add(AutoImport.Never()))