本文整理汇总了C#中ModelMapper.AddMapping方法的典型用法代码示例。如果您正苦于以下问题:C# ModelMapper.AddMapping方法的具体用法?C# ModelMapper.AddMapping怎么用?C# ModelMapper.AddMapping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelMapper
的用法示例。
在下文中一共展示了ModelMapper.AddMapping方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
public static void Initialize(TestContext context)
{
var cfg = new Configuration();
cfg.DataBaseIntegration(x => {
x.ConnectionString = "Server=localhost;Database=test;Uid=root;Pwd=kmn23po;";
x.Driver<MySqlDataDriver>();
x.Dialect<MySQLDialect>();
x.LogSqlInConsole = true;
x.BatchSize = 30;
});
var mapper = new ModelMapper();
mapper.AddMapping<ParentMap>();
mapper.AddMapping<ParentWithGuidMap>();
mapper.AddMapping<ChildMap>();
cfg.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
sessionFactory = cfg.BuildSessionFactory();
var schemaUpdate = new SchemaUpdate(cfg);
schemaUpdate.Execute(false, true);
InsertData();
}
示例2: GetMappings
protected override HbmMapping GetMappings()
{
var mapper = new ModelMapper();
mapper.AddMapping<PersonMapper>();
mapper.AddMapping<CachedPersonMapper>();
return mapper.CompileMappingForAllExplicitlyAddedEntities();
}
示例3: CompiledMappings_ShouldNotDependOnAddedOrdering_AddedBy_AddMapping
public void CompiledMappings_ShouldNotDependOnAddedOrdering_AddedBy_AddMapping()
{
var mapper = new ModelMapper();
mapper.AddMapping<EntityMapping>();
mapper.AddMapping<DerivedClassMapping>();
mapper.AddMapping<BaseClassMapping>();
var config = TestConfigurationHelper.GetDefaultConfiguration();
Assert.DoesNotThrow(() => config.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities()));
}
示例4: GetMappings
private static HbmMapping GetMappings()
{
var mapper = new ModelMapper();
mapper.AddMapping<BlogPostMapping>();
mapper.AddMapping<CommentMapping>();
HbmMapping mapping = mapper.CompileMappingFor(new[] { typeof(BlogPost), typeof(Comment) });
return mapping;
}
示例5: CreateMapper
private IEnumerable<HbmMapping> CreateMapper()
{
var mapper = new ModelMapper();
mapper.AddMapping<XmlAsStringEntityMap>();
mapper.AddMapping<XmlEntityMap>();
mapper.AddMapping<BinaryEntityMap>();
mapper.AddMapping<ProtobufEntityMap>();
mapper.AddMapping<JsonEntityMap>();
return mapper.CompileMappingForEachExplicitlyAddedEntity();
}
示例6: ExportSchema
public void ExportSchema()
{
// Inicio do Setup do NH
var config = new Configuration();
config.DataBaseIntegration(
db =>
{
db.Dialect<MsSql2008Dialect>();
db.ConnectionStringName = "DefaultNH";
db.SchemaAction = SchemaAutoAction.Recreate;
});
ModelMapper modelMapper = new ModelMapper();
modelMapper.AddMapping<ProdutoNHMap>();
modelMapper.AddMapping<DepartamentoNHMap>();
config.AddDeserializedMapping(modelMapper.CompileMappingForAllExplicitlyAddedEntities(), "Domain");
ISessionFactory sessionFactory = config.BuildSessionFactory();
// Fim do Setup do NH - Isso deve ficar no start da app (Global.asax por exemplo)
using (var session = sessionFactory.OpenSession())
{
// Criteria API
// HQL
// Linq
var produtosAcima1000 = session.QueryOver<Produto>().List();
foreach (var produto in produtosAcima1000)
{
Console.WriteLine(produto);
}
}
using (var session = sessionFactory.OpenSession())
{
var produto = new Produto();
produto.Nome = "Teste #1";
produto.Preco = 90;
produto.Quantidade = 123;
produto.Ativo = true;
session.Save(produto);
session.Flush();
}
}
示例7: CreateSessionFactory
public static ISessionFactory CreateSessionFactory()
{
var configuration = new Configuration();
configuration.Configure();
var mapper = new ModelMapper();
mapper.AddMapping<FileMapping>();
mapper.AddMapping<CinemaMapping>();
mapper.AddMapping<LanguageMapping>();
mapper.AddMapping<CompanyMapping>();
configuration.AddDeserializedMapping(mapper.CompileMappingForAllExplicitlyAddedEntities(), null);
var factory = configuration.BuildSessionFactory();
new SchemaUpdate(configuration).Execute(false, true);
return factory;
}
示例8: CreateSessionFactory
/// <summary>
/// Creates session factory
/// </summary>
/// <param name="configurationReader">configuration reader</param>
/// <returns></returns>
private static ISessionFactory CreateSessionFactory(IConfigurationReader configurationReader)
{
var configuration = new NHibernate.Cfg.Configuration();
configuration.SessionFactoryName("Jumblocks Blog");
configuration.DataBaseIntegration(db =>
{
db.Dialect<MsSql2008FixedDialect>();
db.IsolationLevel = IsolationLevel.ReadCommitted;
db.ConnectionString = configurationReader.ConnectionStrings["BlogDb"].ConnectionString;
db.BatchSize = 100;
//for testing
db.LogFormattedSql = true;
db.LogSqlInConsole = true;
db.AutoCommentSql = true;
});
var mapper = new ModelMapper();
mapper.AddMapping<BlogPostMap>();
mapper.AddMapping<BlogUserMap>();
mapper.AddMapping<ImageReferenceMap>();
mapper.AddMapping<TagMap>();
mapper.AddMapping<SeriesMap>();
mapper.AddMapping<UserMap>();
mapper.AddMapping<RoleMap>();
mapper.AddMapping<OperationMap>();
configuration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
configuration.CurrentSessionContext<WebSessionContext>();
return configuration.BuildSessionFactory();
}
示例9: Configure
public static void Configure()
{
var config = new Configuration().Configure();
var mapper = new ModelMapper();
mapper.AddMapping<UserMap>();
mapper.AddMapping<RoleMap>();
mapper.AddMapping<PostMap>();
mapper.AddMapping<TagMap>();
config.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
_sessionFactory = config.BuildSessionFactory();
}
示例10: ApplyMappings
void ApplyMappings(Configuration config)
{
var mapper = new ModelMapper();
mapper.AddMapping<OutboxEntityMap>();
config.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
}
示例11: LoadMappingFrom
public static HbmMapping LoadMappingFrom(params Assembly[] assemblies)
{
Require.NotNull(assemblies, "assemblies");
var baseTypes = new Type[] {
typeof(ClassMapping<>),
typeof(JoinedSubclassMapping<>),
typeof(UnionSubclassMapping<>),
typeof(SubclassMapping<>)
};
var mapper = new ModelMapper();
foreach (var asm in assemblies)
{
foreach (var type in asm.GetTypes())
{
if (!type.IsClass || type.IsAbstract || type.IsInterface || !type.BaseType.IsGenericType) continue;
if (!baseTypes.Contains(type.BaseType.GetGenericTypeDefinition())) continue;
mapper.AddMapping(type);
}
}
var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
mapping.autoimport = false;
return mapping;
}
示例12: Setup
public void Setup()
{
var mapper = new ModelMapper();
mapper.AddMapping<OutboxEntityMap>();
var configuration = new global::NHibernate.Cfg.Configuration()
.AddProperties(new Dictionary<string, string>
{
{ "dialect", dialect },
{ global::NHibernate.Cfg.Environment.ConnectionString,connectionString }
});
configuration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
new SchemaUpdate(configuration).Execute(false, true);
SessionFactory = configuration.BuildSessionFactory();
Session = SessionFactory.OpenSession();
persister = new OutboxPersister
{
StorageSessionProvider = new FakeSessionProvider(SessionFactory, Session),
EndpointName = "TestEndpoint"
};
}
示例13: AsyncMain
static async Task AsyncMain()
{
Console.Title = "Samples.SqlNHibernate.Receiver";
Configuration hibernateConfig = new Configuration();
hibernateConfig.DataBaseIntegration(x =>
{
x.ConnectionStringName = "NServiceBus/Persistence";
x.Dialect<MsSql2012Dialect>();
});
#region NHibernate
hibernateConfig.SetProperty("default_schema", "receiver");
#endregion
ModelMapper mapper = new ModelMapper();
mapper.AddMapping<OrderMap>();
hibernateConfig.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
new SchemaExport(hibernateConfig).Execute(false, true, false);
#region ReceiverConfiguration
EndpointConfiguration endpointConfiguration = new EndpointConfiguration("Samples.SqlNHibernate.Receiver");
endpointConfiguration.SendFailedMessagesTo("error");
endpointConfiguration.AuditProcessedMessagesTo("audit");
endpointConfiguration.EnableInstallers();
endpointConfiguration.UseTransport<SqlServerTransport>()
.DefaultSchema("receiver")
.UseSpecificSchema(e =>
{
if (e == "error" || e == "audit")
{
return "dbo";
}
if (e == "Samples.SqlNHibernate.Sender")
{
return "sender";
}
return null;
});
endpointConfiguration.UsePersistence<NHibernatePersistence>()
.UseConfiguration(hibernateConfig);
#endregion
IEndpointInstance endpoint = await Endpoint.Start(endpointConfiguration);
try
{
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
finally
{
await endpoint.Stop();
}
}
示例14: GetMappings
protected static HbmMapping GetMappings()
{
//There is a dynamic way to do this, but for simplicity I chose to hard code
var mapper = new ModelMapper();
mapper.AddMapping<UsersMap>();
var mapping = mapper.CompileMappingFor(new[] { typeof(Users) });
return mapping;
}
示例15: NHMigrationDemoConfig
public NHMigrationDemoConfig()
{
this.DataBaseIntegration(db =>
{
db.ConnectionString = "Data Source=(local);initial catalog=NHMigrationDemo;Integrated Security=SSPI";
db.Dialect<MsSql2012Dialect>();
db.BatchSize = 150;
db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
db.LogFormattedSql = true;
});
var mapper = new ModelMapper();
mapper.AddMapping(new CatMapping());
mapper.AddMapping(new DogMapping());
this.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
this.UseTableBasedMigrations("NHMigrationDemoConfig");
this.RegisterAllMigrationsFrom(GetType().Assembly);
}