本文整理汇总了C#中NHibernate.Mapping.ByCode.ConventionModelMapper类的典型用法代码示例。如果您正苦于以下问题:C# ConventionModelMapper类的具体用法?C# ConventionModelMapper怎么用?C# ConventionModelMapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConventionModelMapper类属于NHibernate.Mapping.ByCode命名空间,在下文中一共展示了ConventionModelMapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetIdentityMappings
/// <summary>
/// Gets a mapping that can be used with NHibernate.
/// </summary>
/// <param name="additionalTypes">Additional Types that are to be added to the mapping, this is useful for adding your ApplicationUser class</param>
/// <returns></returns>
public static HbmMapping GetIdentityMappings(System.Type[] additionalTypes)
{
var baseEntityToIgnore = new[] {
typeof(NHibernate.AspNet.Identity.DomainModel.EntityWithTypedId<int>),
typeof(NHibernate.AspNet.Identity.DomainModel.EntityWithTypedId<string>),
};
var allEntities = new List<System.Type> {
typeof(ApplicationTenant),
typeof(IdentityUser),
typeof(IdentityRole),
typeof(IdentityUserLogin),
typeof(IdentityUserClaim),
};
allEntities.AddRange(additionalTypes);
var mapper = new ConventionModelMapper();
DefineBaseClass(mapper, baseEntityToIgnore.ToArray());
mapper.IsComponent((type, declared) => typeof(NHibernate.AspNet.Identity.DomainModel.ValueObject).IsAssignableFrom(type));
mapper.AddMapping<IdentityUserMap>();
mapper.AddMapping<IdentityRoleMap>();
mapper.AddMapping<IdentityUserClaimMap>();
mapper.AddMapping<ApplicationTenantMap>();
return mapper.CompileMappingFor(allEntities);
}
示例2: NHibernateHelper
static NHibernateHelper()
{
try
{
cfg = new Configuration();
cfg.Configure("NHibernateQueryModelConfiguration.xml");
var mapper = new ConventionModelMapper();
//mapper.IsEntity((t, declared) => t.Namespace.StartsWith("Sample.QueryModel") || );
mapper.AfterMapClass += (inspector, type, classCustomizer) =>
{
classCustomizer.Lazy(false);
//classCustomizer.Id(m => m.Generator(new GuidGeneratorDef()));
};
var mapping = mapper.CompileMappingFor(
Assembly.Load("Sample.QueryModel").GetExportedTypes()
.Union(new Type[] {typeof(Version)}));
var allmapping = mapping.AsString();
cfg.AddDeserializedMapping(mapping, "AutoModel");
_sessionFactory = cfg.BuildSessionFactory();
}
catch (Exception ex)
{
throw ex;
}
}
示例3: GetMappings
protected override HbmMapping GetMappings()
{
var mapper = new ConventionModelMapper();
// Working Example
//mapper.Class<Toy>(rc => rc.Set(x => x.Animals, cmap => { }, rel => rel.ManyToAny<int>(meta =>
// {
// meta.MetaValue(1, typeof (Cat));
// meta.MetaValue(2, typeof (Dog));
// })));
// User needs
mapper.Class<Toy>(rc => rc.Set(x => x.Animals, cmap =>
{
cmap.Table("Animals_Toys");
cmap.Key(km => km.Column("Cat_Id"));
}, rel => rel.ManyToAny<int>(meta =>
{
meta.MetaValue(1, typeof(Cat));
meta.MetaValue(2, typeof(Dog));
meta.Columns(cid =>
{
cid.Name("Animal_Id");
cid.NotNullable(true);
}, ctype =>
{
ctype.Name("Animal_Type");
ctype.NotNullable(true);
});
})));
var mappings = mapper.CompileMappingFor(new[] { typeof(Cat), typeof(Dog), typeof(Toy) });
//Console.WriteLine(mappings.AsString()); // <=== uncomment this line to see the XML mapping
return mappings;
}
示例4: MappingEngine
/// <summary>
/// Initializes a new instance of the <see cref="MappingEngine"/> class
/// </summary>
/// <param name="rootConfig">The root configuration</param>
/// <param name="nhConfig">The current NH configuration</param>
/// <param name="modelMapper">The model mapper</param>
public MappingEngine(FirehawkConfig rootConfig, Configuration nhConfig, ConventionModelMapper modelMapper)
{
this.rootConfig = rootConfig;
this.nhConfig = nhConfig;
this.modelMapper = modelMapper;
this.namingEngine = new NamingEngine(rootConfig.NamingConventionsConfig);
}
示例5: Main
static void Main(string[] args)
{
SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
var mapper = new ConventionModelMapper();
mapper.Class<SomeAreaClass>(c =>
{
c.Property(x => x.Area, m =>
{
m.Type<MsSql2008GeographyType>();
m.NotNullable(true);
});
});
var cfg = new Configuration()
.DataBaseIntegration(db =>
{
db.ConnectionString = "YourConnectionString";
db.Dialect<MsSql2012GeographyDialect>();
});
cfg
.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
cfg
.AddAuxiliaryDatabaseObject(new SpatialAuxiliaryDatabaseObject(cfg));
new SchemaExport(cfg).Execute(false, true, false);
}
示例6: ExplicitMapping
static void ExplicitMapping(ConventionModelMapper mapper)
{
mapper.Class<Master>(x =>
{
x.Id(y => y.Id, y => y.Generator(Generators.HighLow));
x.Set(y => y.Options, y =>
{
y.Key(z => z.Column("master_id"));
y.Table("master_option");
}, y =>
{
y.ManyToMany(z =>
{
z.Column("option_id");
});
});
});
mapper.Class<Option>(x =>
{
x.Id(y => y.Id, y => y.Generator(Generators.HighLow));
x.Set(y => y.Masters, y =>
{
y.Key(z => z.Column("option_id"));
y.Table("master_option");
y.Inverse(true);
}, y =>
{
y.ManyToMany(z =>
{
z.Column("master_id");
});
});
});
}
示例7: TestFixtureSetUp
public void TestFixtureSetUp()
{
configuration = new Configuration();
configuration.SessionFactory()
.Integrate.Using<SQLiteDialect>()
.Connected.Using("Data source=testdb")
.AutoQuoteKeywords()
.LogSqlInConsole()
.EnableLogFormattedSql();
var mapper = new ConventionModelMapper();
mapper.Class<Foo>(cm => { });
mapper.Class<Bar>(cm => { });
CustomizeMapping(mapper);
var mappingDocument = mapper.CompileMappingForAllExplicitlyAddedEntities();
new XmlSerializer(typeof(HbmMapping)).Serialize(Console.Out, mappingDocument);
configuration.AddDeserializedMapping(mappingDocument, "Mappings");
new SchemaExport(configuration).Create(true, true);
sessionFactory = configuration.BuildSessionFactory();
using (var session = sessionFactory.OpenSession())
using (var tx = session.BeginTransaction())
{
var foo = new Foo { Bars = CreateCollection() };
foo.Bars.Add(new Bar { Data = 1 });
foo.Bars.Add(new Bar { Data = 2 });
id = session.Save(foo);
tx.Commit();
}
sessionFactory.Statistics.IsStatisticsEnabled = true;
}
示例8: ConventionsMapper
public ConventionsMapper()
{
this.conventionModelMapper = new ConventionModelMapper();
var baseEntityType = typeof(Entity);
this.conventionModelMapper.IsEntity((t, declared) => baseEntityType.IsAssignableFrom(t) && baseEntityType != t && !t.IsInterface);
this.conventionModelMapper.IsRootEntity((t, declared) => baseEntityType.Equals(t.BaseType));
this.conventionModelMapper.Class<Entity>(map => {
map.Id(x => x.Id, m => m.Generator(Generators.Identity));
map.Id(x => x.Id, m => m.Column("id"));
map.Version(x => x.Version, m => m.Generated(VersionGeneration.Always));
map.Version(x => x.Version, m => m.Column("version"));
});
this.conventionModelMapper.BeforeMapProperty += (insp, prop, map) => map.Column(prop.LocalMember.Name);
this.conventionModelMapper.BeforeMapManyToOne += (insp, prop, map) => map.Column(prop.LocalMember.GetPropertyOrFieldType().Name + "Id");
this.conventionModelMapper.BeforeMapManyToOne += (insp, prop, map) => map.Cascade(Cascade.Persist);
this.conventionModelMapper.BeforeMapBag += (insp, prop, map) => map.Table(prop.GetContainerEntity(insp).Name + prop.GetRootMember().Name);
this.conventionModelMapper.BeforeMapBag += (insp, prop, map) => map.Key(km => km.Column(prop.GetContainerEntity(insp).Name + "Id"));
this.conventionModelMapper.BeforeMapBag += (insp, prop, map) => map.Cascade(Cascade.All);
this.conventionModelMapper.BeforeMapClass += (insp, prop, map) => map.Table(prop.Name);
this.conventionModelMapper.AddMappings(typeof(RestaurantMappings).Assembly.GetTypes());
this.mapping = this.conventionModelMapper.CompileMappingFor(baseEntityType.Assembly.GetExportedTypes().Where(t => t.Namespace != null && t.Namespace.EndsWith("Entities")));
}
示例9: Initialize
public static Configuration Initialize()
{
INHibernateConfigurationCache cache = new NHibernateConfigurationFileCache();
var mappingAssemblies = new[] {
typeof(ActionConfirmation<>).Assembly.GetName().Name
};
var configuration = cache.LoadConfiguration(CONFIG_CACHE_KEY, null, mappingAssemblies);
if (configuration == null) {
configuration = new Configuration();
configuration
.Proxy(p => p.ProxyFactoryFactory<DefaultProxyFactoryFactory>())
.DataBaseIntegration(db => {
db.ConnectionStringName = "DonSharpLiteConnectionString";
db.Dialect<MsSql2008Dialect>();
})
.AddAssembly(typeof(ActionConfirmation<>).Assembly)
.CurrentSessionContext<LazySessionContext>();
var mapper = new ConventionModelMapper();
mapper.WithConventions(configuration);
cache.SaveConfiguration(CONFIG_CACHE_KEY, configuration);
}
return configuration;
}
示例10: Configure
public static void Configure(ISessionStorage storage)
{
var baseEntityToIgnore = new[] {
typeof(NHibernate.AspNet.Identity.DomainModel.EntityWithTypedId<int>),
typeof(NHibernate.AspNet.Identity.DomainModel.EntityWithTypedId<string>),
};
var allEntities = new[] {
typeof(IdentityUser),
typeof(ApplicationUser),
typeof(IdentityRole),
typeof(IdentityUserLogin),
typeof(IdentityUserClaim),
};
var mapper = new ConventionModelMapper();
DefineBaseClass(mapper, baseEntityToIgnore);
mapper.IsComponent((type, declared) => typeof(NHibernate.AspNet.Identity.DomainModel.ValueObject).IsAssignableFrom(type));
mapper.AddMapping<IdentityUserMap>();
mapper.AddMapping<IdentityRoleMap>();
mapper.AddMapping<IdentityUserClaimMap>();
var mapping = mapper.CompileMappingFor(allEntities);
System.Diagnostics.Debug.WriteLine(mapping.AsString());
var configuration = NHibernateSession.Init(storage, mapping);
BuildSchema(configuration);
}
示例11: GetIdentityMappings
/// <summary>
/// Gets a mapping that can be used with NHibernate.
/// </summary>
/// <param name="additionalTypes">Additional Types that are to be added to the mapping, this is useful for adding your ApplicationUser class</param>
/// <returns></returns>
public static HbmMapping GetIdentityMappings(System.Type[] additionalTypes)
{
var baseEntityToIgnore = new[]
{
typeof(EntityWithTypedId<int>),
typeof(EntityWithTypedId<string>)
};
// Modified for NS: PIMS.Infrastructure.NHibernate.NHAspNetIdentity
var allEntities = new List<System.Type> {
typeof(IdentityUser),
typeof(IdentityRole),
typeof(IdentityUserLogin),
typeof(IdentityUserClaim),
};
allEntities.AddRange(additionalTypes);
var mapper = new ConventionModelMapper();
DefineBaseClass(mapper, baseEntityToIgnore.ToArray());
mapper.IsComponent((type, declared) => typeof(ValueObject).IsAssignableFrom(type));
// Modified for NS: PIMS.Infrastructure.NHibernate.NHAspNetIdentity
mapper.AddMapping<IdentityUserMap>();
mapper.AddMapping<IdentityRoleMap>();
mapper.AddMapping<IdentityUserClaimMap>();
return mapper.CompileMappingFor(allEntities);
}
示例12: CustomizeMapping
protected override void CustomizeMapping(ConventionModelMapper mapper)
{
mapper.Class<Foo>(cm => cm.List(x => x.Bars, bpm =>
{
bpm.Cascade(Cascade.All);
bpm.Type<PersistentQueryableListType<Bar>>();
}));
}
示例13: GetMappings
protected override HbmMapping GetMappings()
{
var mapper = new ConventionModelMapper();
mapper.IsTablePerClass((type, declared) => false);
mapper.IsTablePerClassHierarchy((type, declared) => true);
var mappings = mapper.CompileMappingFor(new[] {typeof (Animal), typeof (Reptile), typeof (Mammal), typeof (Lizard), typeof (Dog), typeof (Cat)});
return mappings;
}
示例14: WhenPoidNoSetterThenApplyNosetter
public void WhenPoidNoSetterThenApplyNosetter()
{
var mapper = new ConventionModelMapper();
mapper.Class<MyClass>(x => x.Id(mc=> mc.Id));
var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
var hbmClass = hbmMapping.RootClasses[0];
hbmClass.Id.access.Should().Be("nosetter.camelcase-underscore");
}
示例15: WhenAutoPropertyNoAccessor
public void WhenAutoPropertyNoAccessor()
{
var mapper = new ConventionModelMapper();
var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
var hbmClass = hbmMapping.RootClasses[0];
var hbmProperty = hbmClass.Properties.Single(x => x.Name == "AProp");
hbmProperty.Access.Should().Be.NullOrEmpty();
}