本文整理汇总了C#中NHibernate.AddDeserializedMapping方法的典型用法代码示例。如果您正苦于以下问题:C# NHibernate.AddDeserializedMapping方法的具体用法?C# NHibernate.AddDeserializedMapping怎么用?C# NHibernate.AddDeserializedMapping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NHibernate
的用法示例。
在下文中一共展示了NHibernate.AddDeserializedMapping方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MapTypes
public virtual void MapTypes(List<Type> allTypes, NHibernate.Cfg.Configuration cfg, Func<string, string> formatter)
{
var m = new HbmMapping();
m.Items = allTypes.Select(t =>
{
var sc = new HbmSubclass();
sc.name = GetName(t);
sc.extends = GetName(t.BaseType);
sc.discriminatorvalue = map.GetOrCreateDefinition(t).Discriminator ?? t.Name;
sc.lazy = false;
sc.lazySpecified = true;
var propertyMappings = GetPersistables(t)
.Select(p => p.Attribute.GetPropertyMapping(p.DeclaringProperty, formatter))
.ToList();
if (propertyMappings.Count > 0)
{
if (sc.Items == null)
sc.Items = propertyMappings.ToArray();
else
sc.Items = sc.Items.Union(propertyMappings).ToArray();
}
logger.DebugFormat("Generating subclass {0} with discriminator {1} extending {2} with {3} items ({4} property mappings)", sc.name, sc.discriminatorvalue, sc.extends, sc.Items != null ? sc.Items.Length.ToString() : "(null)", propertyMappings.Count);
return sc;
}).ToArray();
if (Debugger.IsAttached)
{
var dbg = m.AsString();
}
cfg.AddDeserializedMapping(m, "N2");
}
示例2: MapTypes
public virtual void MapTypes(List<Type> allTypes, NHibernate.Cfg.Configuration cfg, Func<string, string> formatter)
{
var m = new HbmMapping();
m.Items = allTypes.Select(t =>
{
var sc = new HbmSubclass();
sc.name = GetName(t);
sc.extends = GetName(t.BaseType);
sc.discriminatorvalue = map.GetOrCreateDefinition(t).Discriminator ?? t.Name;
sc.lazy = false;
sc.lazySpecified = true;
var propertyMappings = GetPersistables(t)
.Select(p => p.Attribute.GetPropertyMapping(p.DeclaringProperty, formatter))
.ToList();
if (propertyMappings.Count > 0)
{
if (sc.Items == null)
sc.Items = propertyMappings.ToArray();
else
sc.Items = sc.Items.Union(propertyMappings).ToArray();
}
return sc;
}).ToArray();
var dbg = m.AsString();
cfg.AddDeserializedMapping(m, "N2");
}
示例3: AlterConfiguration
public override void AlterConfiguration(NHibernate.Cfg.Configuration cfg)
{
ModelMapper mm = new ModelMapper();
mm.Class<FileSystemItem>(FileSystemItemCustomization);
mm.Class<FileSystemChunk>(FileSystemChunkCustomization);
var compiledMapping = mm.CompileMappingForAllExplicitlyAddedEntities();
cfg.AddDeserializedMapping(compiledMapping, "N2");
}
示例4: AlterConfiguration
public override void AlterConfiguration(NHibernate.Cfg.Configuration cfg)
{
ModelMapper mm = new ModelMapper();
mm.Class<Bucket>(BucketCustomization);
mm.Class<Statistic>(StatisticCustomization);
var compiledMapping = mm.CompileMappingForAllExplicitlyAddedEntities();
cfg.AddDeserializedMapping(compiledMapping, "N2");
}
示例5: ConfigureMapping
public override void ConfigureMapping(NHibernate.Cfg.Configuration configuration)
{
var mapper = new ConventionModelMapper();
mapper.BeforeMapProperty += (inspector, member, customizer) =>
{
if (member.LocalMember.GetPropertyOrFieldType() == typeof(string))
{
customizer.Length(50);
}
};
mapper.BeforeMapClass += (inspector, type, customizer) => customizer.Id(im => im.Generator(Generators.GuidComb));
// define the mapping shape
mapper.Class<Hotel>(ca => ca.List(item => item.Reservations, cm => cm.Key(km => km.Column("HotelId"))));
mapper.Class<Room>(ca => ca.List(item => item.Reservations, cm => cm.Key(km =>
{
km.Column("RoomId");
km.OnDelete(OnDeleteAction.NoAction);
})));
mapper.Class<Reservation>(ca =>
{
ca.ManyToOne(item => item.Hotel, m => { m.Column("HotelId"); m.Insert(false); m.Update(false); m.Lazy(LazyRelation.Proxy);} );
ca.ManyToOne(item => item.Room, m => { m.Column("RoomId"); m.Insert(false); m.Update(false); m.Lazy(LazyRelation.Proxy); });
});
// list all the entities we want to map.
IEnumerable<Type> baseEntities = GetMappingTypes();
// compile the mapping for the specified entities
HbmMapping mappingDocument = mapper.CompileMappingFor(baseEntities);
// inject the mapping in NHibernate
configuration.AddDeserializedMapping(mappingDocument, "Domain");
// fix up the schema
SchemaMetadataUpdater.QuoteTableAndColumns(configuration);
SessionFactory.SessionFactoryInstance = configuration.BuildSessionFactory();
}
示例6: ConfigureMapping
public override void ConfigureMapping(NHibernate.Cfg.Configuration configuration)
{
var orm = new ObjectRelationalMapper();
var mapper = new Mapper(orm);
mapper.AddPropertyPattern(mi => TypeExtensions.GetPropertyOrFieldType(mi) == typeof(string), pm => pm.Length(50));
orm.Patterns.PoidStrategies.Add(new NativePoidPattern());
orm.Patterns.PoidStrategies.Add(new GuidOptimizedPoidPattern());
// list all the entities we want to map.
IEnumerable<Type> baseEntities = GetMappingTypes();
// we map all classes as Table per class
orm.TablePerClass(baseEntities);
mapper.Customize<Hotel>(ca => ca.Collection(item => item.Reservations, cm => cm.Key(km => km.Column("HotelId"))));
mapper.Customize<Room>(ca => ca.Collection(item => item.Reservations, cm => cm.Key(km =>
{
km.Column("RoomId");
km.OnDelete(OnDeleteAction.NoAction);
})));
mapper.Customize<Reservation>(ca =>
{
ca.ManyToOne(item => item.Hotel, m => { m.Column("HotelId"); m.Insert(false); m.Update(false); m.Lazy(LazyRelation.Proxy); });
ca.ManyToOne(item => item.Room, m => { m.Column("RoomId"); m.Insert(false); m.Update(false); m.Lazy(LazyRelation.Proxy); });
});
// compile the mapping for the specified entities
HbmMapping mappingDocument = mapper.CompileMappingFor(baseEntities);
// inject the mapping in NHibernate
configuration.AddDeserializedMapping(mappingDocument, "Domain");
// fix up the schema
SchemaMetadataUpdater.QuoteTableAndColumns(configuration);
SessionFactory.SessionFactoryInstance = configuration.BuildSessionFactory();
}
示例7: AddMapping
/// <summary>Adds mappings to the configuration.</summary>
/// <param name="cfg">The configuration to add the mappings to.</param>
/// <param name="name">The resource name of the embedded resource.</param>
protected virtual void AddMapping(NHibernate.Cfg.Configuration cfg, string name)
{
if (!string.IsNullOrEmpty(name))
{
using (Stream stream = GetStreamFromName(name))
{
if (stream == null) throw new ArgumentException("Could not read stream from embedded resource '" + name + "'", "name");
using (StreamReader reader = new StreamReader(stream))
{
var mappingXml = reader.ReadToEnd();
mappingXml = FormatMapping(mappingXml);
var xmlReader = new XmlTextReader(mappingXml, XmlNodeType.Document, null);
var mappingDocument = cfg.LoadMappingDocument(xmlReader, "N2");
cfg.AddDeserializedMapping(mappingDocument.Document, mappingDocument.Name);
}
}
}
}
示例8: AddDefaultMapping
protected virtual void AddDefaultMapping(NHibernate.Cfg.Configuration cfg)
{
ModelMapper mm = new ModelMapper();
mm.Class<ContentItem>(ContentItemCustomization);
mm.Class<ContentDetail>(ContentDetailCustomization);
mm.Class<DetailCollection>(DetailCollectionCustomization);
mm.Class<AuthorizedRole>(AuthorizedRoleCustomization);
mm.Class<ContentVersion>(ContentVersionCustomization);
var compiledMapping = mm.CompileMappingForAllExplicitlyAddedEntities();
cfg.AddDeserializedMapping(compiledMapping, "N2");
}