本文整理汇总了C#中ModelMapper.AddMappings方法的典型用法代码示例。如果您正苦于以下问题:C# ModelMapper.AddMappings方法的具体用法?C# ModelMapper.AddMappings怎么用?C# ModelMapper.AddMappings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelMapper
的用法示例。
在下文中一共展示了ModelMapper.AddMappings方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FactoryProvider
static FactoryProvider()
{
var modelInspector = new MySimpleModelInspector();
Assert.IsNotNull(new Entity());
var mapper = new ModelMapper(modelInspector);
mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());
mapper.BeforeMapClass += (mi, type, map) =>
map.Id(idmap => idmap.Generator(Generators.HighLow,
gmap => gmap.Params(new
{
table = "NextHighVaues",
column = "NextHigh",
max_lo = 100,
where = String.Format("EntityName = '{0}'", type.Name.ToLowerInvariant())
})));
mapper.BeforeMapClass += (mi, t, map) => map.Table(t.Name.ToLowerInvariant());
mapper.BeforeMapJoinedSubclass += (mi, t, map) => map.Table(t.Name.ToLowerInvariant());
mapper.BeforeMapUnionSubclass += (mi, t, map) => map.Table(t.Name.ToLowerInvariant());
mapper.BeforeMapProperty += (mi, propertyPath, map) =>
{
if (typeof(decimal).Equals(propertyPath.LocalMember.GetPropertyOrFieldType()))
{
map.Type(NHibernateUtil.Currency);
}
};
mapper.BeforeMapBag += (mi, propPath, map) =>
{
map.Cascade(Cascade.All.Include(Cascade.DeleteOrphans));
map.BatchSize(10);
};
mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());
var domainMapping = mapper.CompileMappingForEachExplicitlyAddedEntity();
domainMapping.WriteAllXmlMapping();
var configuration = new Configuration();
configuration.DataBaseIntegration(c =>
{
c.Dialect<MsSql2008Dialect>();
c.ConnectionString = @"Data Source=localhost\SQLEXPRESS;Initial Catalog=IntroNH;Integrated Security=True;Pooling=False";
c.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
c.SchemaAction = SchemaAutoAction.Create;
});
foreach(var mapping in domainMapping)
{
configuration.AddMapping(mapping);
}
configuration.AddAuxiliaryDatabaseObject(CreateHighLowScript(modelInspector, Assembly.GetExecutingAssembly().GetExportedTypes()));
Factory=configuration.BuildSessionFactory();
}
示例2: GenerateSchema
public static void GenerateSchema()
{
Configuration cfg = new Configuration();
//cfg.SetProperty("nhibernate.envers.default_schema", "audit");
cfg.AddAuxiliaryDatabaseObject(new SpatialAuxiliaryDatabaseObject(cfg));
var mapper = new ModelMapper();
mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());
HbmMapping mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
cfg.AddMapping(mapping);
cfg.AddAssembly(typeof(Model).Assembly);
//cfg.IntegrateWithEnvers();
cfg.Configure();
new NHibernate.Tool.hbm2ddl.SchemaExport(cfg)
.SetDelimiter(";")
//.SetOutputFile("schema.sql")
.Execute(false, true, false);
}
示例3: BuildProjectsSessionFactory
private ISessionFactory BuildProjectsSessionFactory()
{
// register nhibernate
var file = "deal.cat";
if (ChiffrageWPF.Properties.Settings.Default.DealsRecentPath != null && ChiffrageWPF.Properties.Settings.Default.DealsRecentPath.Count > 0)
{
file = ChiffrageWPF.Properties.Settings.Default.DealsRecentPath[ChiffrageWPF.Properties.Settings.Default.DealsRecentPath.Count - 1];
}
var dealConfiguration = new Configuration()
.Proxy(p => p.ProxyFactoryFactory<NHibernate.Bytecode.DefaultProxyFactoryFactory>())
.DataBaseIntegration(d =>
{
d.ConnectionString = string.Format("Data Source={0};Version=3;", file);
d.Dialect<SQLiteDialect>();
d.SchemaAction = SchemaAutoAction.Update;
});
var dealMapper = new ModelMapper();
dealMapper.AddMappings(typeof(DealRepository).Assembly.GetTypes());
HbmMapping dealMapping = dealMapper.CompileMappingForAllExplicitlyAddedEntities();
dealConfiguration.AddMapping(dealMapping);
return dealConfiguration.BuildSessionFactory();
}
示例4: CreateMapping
private static HbmMapping CreateMapping()
{
var mapper = new ModelMapper();
mapper.AddMappings(GetMappingTypes());
return mapper.CompileMappingForAllExplicitlyAddedEntities();
}
示例5: BuildSessionFactory
private ISessionFactory BuildSessionFactory()
{
var mapper = new ModelMapper();
var configuration = new Configuration();
mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());
configuration.DataBaseIntegration(c =>
{
c.ConnectionString = _connectionString;
c.IsolationLevel = IsolationLevel.ReadCommitted;
c.Driver<Sql2008ClientDriver>();
c.Dialect<MsSql2008Dialect>();
c.BatchSize = 50;
c.Timeout = 30;
#if DEBUG
c.LogSqlInConsole = true;
c.LogFormattedSql = true;
c.AutoCommentSql = true;
#endif
});
#if DEBUG
configuration.SessionFactory().GenerateStatistics();
#endif
configuration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
var sessionFactory = configuration.BuildSessionFactory();
return sessionFactory;
}
示例6: GetMappings
private static HbmMapping GetMappings()
{
var mapper = new ModelMapper();
mapper.AddMappings(typeof(SessionHelper).Assembly.GetExportedTypes());
HbmMapping mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
return mapping;
}
示例7: SessionFactory
static SessionFactory()
{
var connectionString = @"Data Source=.\sqlexpress2014;Initial Catalog=BlogDatabase;Integrated Security=True";
var configuration = new Configuration();
configuration.DataBaseIntegration(
x =>
{
x.ConnectionString = connectionString;
x.Driver<SqlClientDriver>();
x.Dialect<MsSql2012Dialect>();
});
configuration.SetProperty(Environment.UseQueryCache, "true");
configuration.SetProperty(Environment.UseSecondLevelCache, "true");
configuration.SetProperty(Environment.CacheProvider, typeof(SysCacheProvider).AssemblyQualifiedName);
var mapper = new ModelMapper();
mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());
mapper.BeforeMapBag += (modelInspector, member1, propertyCustomizer) =>
{
propertyCustomizer.Inverse(true);
propertyCustomizer.Cascade(Cascade.All | Cascade.DeleteOrphans);
};
mapper.BeforeMapManyToOne +=
(modelInspector, member1, propertyCustomizer) => { propertyCustomizer.NotNullable(true); };
mapper.BeforeMapProperty += (inspector, member, customizer) => customizer.NotNullable(true);
var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
configuration.AddMapping(mapping);
sessionFactory = configuration.BuildSessionFactory();
}
示例8: CreateSqlSchema
public void CreateSqlSchema()
{
var sqlBuilder = new SqlConnectionStringBuilder();
sqlBuilder.DataSource = "(local)";
sqlBuilder.InitialCatalog = "nservicebus";
sqlBuilder.IntegratedSecurity = true;
var cfg = new Configuration()
.DataBaseIntegration(x =>
{
x.Dialect<MsSql2008Dialect>();
x.ConnectionString = sqlBuilder.ConnectionString;
});
var mapper = new ModelMapper();
mapper.AddMappings(typeof(NHibernate.Config.SubscriptionMap).Assembly.GetExportedTypes());
HbmMapping faultMappings = mapper.CompileMappingForAllExplicitlyAddedEntities();
cfg.AddMapping(faultMappings);
File.WriteAllText("schema.sql", "");
new SchemaExport(cfg).Create(x => File.AppendAllText("schema.sql", x), true);
subscriptionStorageSessionProvider = new SubscriptionStorageSessionProvider(cfg.BuildSessionFactory());
storage = new SubscriptionStorage(subscriptionStorageSessionProvider);
}
示例9: TestConnection
public void TestConnection()
{
var cfg = new Configuration()
.DataBaseIntegration(db =>
{
db.ConnectionString = "Server=127.0.0.1;Database=troyanda;Uid=postgres;Pwd=qwerty;";
db.Dialect<PostgreSQL94Dialect>();
db.SchemaAction = SchemaAutoAction.Validate;
});
var types = typeof (Cars).Assembly.GetExportedTypes();
/* Add the mapping we defined: */
var mapper = new ModelMapper();
mapper.AddMappings(types);
var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
cfg.AddMapping(mapping);
/* Create a session and execute a query: */
using (ISessionFactory factory = cfg.BuildSessionFactory())
using (ISession session = factory.OpenSession())
using (ITransaction tx = session.BeginTransaction())
{
var car = session.Get<Cars>((long)1);
var worker = new WorkerServices(cfg, session);
var result = worker.GetItemsPresenterForEntity(typeof (Sector));
//session.Save()
tx.Commit();
}
}
示例10: PostProcessConfiguration
protected override void PostProcessConfiguration(global::NHibernate.Cfg.Configuration config)
{
base.PostProcessConfiguration(config);
if (FluentNhibernateMappingAssemblies != null)
{
// add any class mappings in the listed assemblies:
var mapper = new ModelMapper();
foreach (var asm in FluentNhibernateMappingAssemblies.Select(Assembly.Load))
{
mapper.AddMappings(asm.GetTypes());
}
foreach (var mapping in mapper.CompileMappingForEachExplicitlyAddedEntity())
{
config.AddMapping(mapping);
}
foreach (string assemblyName in FluentNhibernateMappingAssemblies)
{
config.AddMappingsFromAssembly(Assembly.Load(assemblyName));
}
}
}
示例11: GetMapping
public static HbmMapping GetMapping()
{
var modelMapper = new ModelMapper();
modelMapper.AddMappings(Assembly.GetAssembly(typeof(PeopleMap)).GetExportedTypes());
HbmMapping mapping = modelMapper.CompileMappingForAllExplicitlyAddedEntities();
return mapping;
}
示例12: AddLoquaciousMappings
static Configuration AddLoquaciousMappings(Configuration nhConfiguration)
{
ModelMapper mapper = new ModelMapper();
mapper.AddMappings(typeof(OrderSagaDataLoquacious).Assembly.GetTypes());
nhConfiguration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
return nhConfiguration;
}
示例13: GetMapper
private static ModelMapper GetMapper()
{
var mapper = new ModelMapper();
mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());
return mapper;
}
示例14: SetUp
public void SetUp()
{
var configuration = new Configuration();
configuration
.SetProperty(NHibernate.Cfg.Environment.GenerateStatistics, "true")
.SetProperty(NHibernate.Cfg.Environment.Hbm2ddlAuto, "create-drop")
.SetProperty(NHibernate.Cfg.Environment.UseQueryCache, "true")
.SetProperty(NHibernate.Cfg.Environment.CacheProvider, typeof (HashtableCacheProvider).AssemblyQualifiedName)
.SetProperty(NHibernate.Cfg.Environment.ReleaseConnections, "on_close")
.SetProperty(NHibernate.Cfg.Environment.Dialect, typeof (SQLiteDialect).AssemblyQualifiedName)
.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, typeof (SQLite20Driver).AssemblyQualifiedName)
.SetProperty(NHibernate.Cfg.Environment.ConnectionString, "Data Source=:memory:;Version=3;New=True;");
var assembly = Assembly.GetExecutingAssembly();
var modelMapper = new ModelMapper();
modelMapper.AddMappings(assembly.GetTypes());
var hbms = modelMapper.CompileMappingForAllExplicitlyAddedEntities();
configuration.AddDeserializedMapping(hbms, assembly.GetName().Name);
ConfigureSearch(configuration);
sessionFactory = configuration.BuildSessionFactory();
Session = sessionFactory.OpenSession();
SearchSession = Search.CreateFullTextSession(Session);
new SchemaExport(configuration)
.Execute(false, true, false, Session.Connection, null);
AfterSetup();
}
示例15: AddFromConfig
private static void AddFromConfig(ModelMapper modelMapper, IList<Assembly> assemblies)
{
for (int i = 0; i < assemblies.Count; ++i)
{
modelMapper.AddMappings(assemblies[i].GetTypes());
}
}