Я новичок в Fluent NHibernate, но меня привлекло Automapping и отличный набор функций платформы. У меня проблемы с получением установки ObservableCollection, я искал в Интернете и пробовал много разных вещей, и все они привели меня к одной и той же ошибке:
FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
---> FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
---> System.ArgumentException: Cannot create an instance of FluentNHibernate.Automapping.AutoMapping`1[uNhAddIns.WPF.Collections.Types.ObservableListType`1[T]] because Type.ContainsGenericParameters is true.
at System.RuntimeType.CreateInstanceCheckThis()
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at FluentNHibernate.Automapping.AutoMapper.ApplyOverrides(Type classType, IList`1 mappedMembers, ClassMappingBase mapping) in d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Automapping\AutoMapper.cs:line 28
at FluentNHibernate.Automapping.AutoMapper.MergeMap(Type classType, ClassMappingBase mapping, IList`1 mappedMembers) in d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Automapping\AutoMapper.cs:line 41
at FluentNHibernate.Automapping.AutoMapper.Map(Type classType, List`1 types) in d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Automapping\AutoMapper.cs:line 176
at FluentNHibernate.Automapping.AutoPersistenceModel.AddMapping(Type type) in d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Automapping\AutoPersistenceModel.cs:line 185
at FluentNHibernate.Automapping.AutoPersistenceModel.CompileMappings() in d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Automapping\AutoPersistenceModel.cs:line 149
at FluentNHibernate.Automapping.AutoPersistenceModel.Configure(Configuration configuration) in d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Automapping\AutoPersistenceModel.cs:line 175
at FluentNHibernate.Cfg.AutoMappingsContainer.Apply(Configuration cfg) in d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Cfg\AutoMappingsContainer.cs:line 84
at FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg) in d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Cfg\MappingConfiguration.cs:line 66
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() in d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 128
--- End of inner exception stack trace ---
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() in d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 139
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 108
--- End of inner exception stack trace ---
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in d:\Builds\FluentNH-v1.x-nh3\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 113
at ToDoIt2.Model.Document.<Initialize>b__0() in C:\data\svn\WPF\vs2010\ToDoIt2\Application\Model\Document.cs:line 54
at ToDoIt2.App.DisplayException(NoArgsDelegate z) in C:\data\svn\WPF\vs2010\ToDoIt2\Application\App.xaml.cs:line 66
Это применимая строка:
---> System.ArgumentException: Cannot create an instance of
FluentNHibernate.Automapping.AutoMapping`1[uNhAddIns.WPF.Collections.Types.ObservableListType`1[T]]
because Type.ContainsGenericParameters is true.
Вот класс, который я пытаюсь отобразить:
public class Item {
public virtual int ItemID { get; set; }
public virtual string Title { get; set; }
public virtual ObservableListType<string> Children { get; set; }
}
Использование uNhAddIns.WPF.Collections.Types.ObservableListType из uNhAddIns.
Вот мое AutoMapping:
this.FluentConfig = Fluently.Configure()
.Mappings(m => m.AutoMappings
.Add(AutoMap
.Assemblies(new ToDoIt2.DB.AutoMapping(),
Assembly.GetExecutingAssembly(),
Assembly.GetAssembly(typeof(ObservableListType<>))
)
.IgnoreBase<pklib.DataObject>()
.Conventions.Add<myPrimaryKeyConvention>()
.Conventions.Add<myForeignKeyConvention>()
));
Ответ от @ Диего
Сущность домена, которую необходимо изменить на:
public class Item {
public virtual int ItemID { get; set; }
public virtual string Title { get; set; }
public virtual ICollection<string> Children { get; set; }
}
Свободная конфигурация изменена на:
this.FluentConfig = Fluently.Configure()
.ExposeConfiguration(cfg => cfg.SetProperty(NHibernate.Cfg.Environment.CollectionTypeFactoryClass,
typeof(WpfCollectionTypeFactory).AssemblyQualifiedName))
.Mappings(m => m.AutoMappings
.Add(AutoMap
.Assemblies(new ToDoIt2.DB.AutoMapping(),
Assembly.GetExecutingAssembly(),
Assembly.GetAssembly(typeof(ObservableListType<>))
)
.IgnoreBase<pklib.DataObject>()
.Conventions.Add<myPrimaryKeyConvention>()
.Conventions.Add<myForeignKeyConvention>()
));