本文整理汇总了C#中ModelMapper.CompileMappingForAllExplicitlyAddedEntities方法的典型用法代码示例。如果您正苦于以下问题:C# ModelMapper.CompileMappingForAllExplicitlyAddedEntities方法的具体用法?C# ModelMapper.CompileMappingForAllExplicitlyAddedEntities怎么用?C# ModelMapper.CompileMappingForAllExplicitlyAddedEntities使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelMapper
的用法示例。
在下文中一共展示了ModelMapper.CompileMappingForAllExplicitlyAddedEntities方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestGenerators
public void TestGenerators()
{
var mapper = new ModelMapper();
mapper.Class<A>(e => { e.Id(c => c.Id, c => c.Generator(Generators.Counter)); });
mapper.Class<B>(e => { e.Id(c => c.Id, c => c.Generator(Generators.UUIDHex)); });
mapper.Class<C>(e => { e.Id(c => c.Id, c => c.Generator(Generators.UUIDString)); });
mapper.Class<D>(e => { e.Id(c => c.Id, c => c.Generator(Generators.Increment)); });
mapper.Class<E>(e => { e.Id(c => c.Id, c => c.Generator(Generators.Select)); });
mapper.Class<F>(e => { e.Id(c => c.Id, c => c.Generator(Generators.SequenceHiLo)); });
mapper.Class<G>(e => { e.Id(c => c.Id, c => c.Generator(Generators.SequenceIdentity)); });
mapper.Class<H>(e => { e.Id(c => c.Id, c => c.Generator(Generators.Table)); });
mapper.Class<I>(e => { e.Id(c => c.Id, c => c.Generator(Generators.TriggerIdentity)); });
var hbmMapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(A).Name)[email protected], Generators.Counter.Class);
Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(B).Name)[email protected], Generators.UUIDHex.Class);
Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(C).Name)[email protected], Generators.UUIDString.Class);
Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(D).Name)[email protected], Generators.Increment.Class);
Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(E).Name)[email protected], Generators.Select.Class);
Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(F).Name)[email protected], Generators.SequenceHiLo.Class);
Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(G).Name)[email protected], Generators.SequenceIdentity.Class);
Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(H).Name)[email protected], Generators.Table.Class);
Assert.AreEqual(hbmMapping.RootClasses.Single(x => x.Name == typeof(I).Name)[email protected], Generators.TriggerIdentity.Class);
}
示例2: AddNHibernateSessionFactory
public static void AddNHibernateSessionFactory(this IServiceCollection services)
{
// By default NHibernate looks for hibernate.cfg.xml
// otherwise for Web it will fallback to web.config
// we got one under wwwroot/web.config
Configuration config = new Configuration();
config.Configure();
// Auto load entity mapping class
ModelMapper mapper = new ModelMapper();
mapper.AddMappings(Assembly.GetAssembly(typeof(Employee)).GetExportedTypes());
HbmMapping mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
config.AddDeserializedMapping(mapping, "NHibernate.Mapping");
SchemaMetadataUpdater.QuoteTableAndColumns(config);
// Drop & Recreate database schema
new SchemaExport(config).Drop(false, true);
new SchemaExport(config).Create(false, true);
// Register services
services.AddSingleton<ISessionFactory>(provider => config.BuildSessionFactory());
services.AddTransient<ISession>(provider => services.BuildServiceProvider().GetService<ISessionFactory>().OpenSession());
}
示例3: InitNHibernate
private static void InitNHibernate()
{
lock (LockObject)
{
if (_sessionFactory == null)
{
// Создание NHibernate-конфигурации приложения на основании описаний из web.config.
// После этого вызова, в том числе, из сборки будут извлечены настройки маппинга,
// заданные в xml-файлах.
var configure = new Configuration().Configure();
// Настройка маппинга, созданного при помощи mapping-by-code
var mapper = new ModelMapper();
mapper.AddMappings(new List<Type>
{
// Перечень классов, описывающих маппинг
typeof (DocumentTypeMap),
typeof (DocumentMap),
typeof (DocumentWithVersionMap),
});
// Добавление маппинга, созданного при помощи mapping-by-code,
// в NHibernate-конфигурацию приложения
configure.AddDeserializedMapping(mapper.CompileMappingForAllExplicitlyAddedEntities(), null);
//configure.LinqToHqlGeneratorsRegistry<CompareValuesGeneratorsRegistry>();
//configure.LinqToHqlGeneratorsRegistry<InGeneratorRegistry>();
configure.DataBaseIntegration(x =>
{
x.LogSqlInConsole = true;
x.LogFormattedSql = true;
});
_sessionFactory = configure.BuildSessionFactory();
}
}
}
示例4: AddLoquaciousMappings
static Configuration AddLoquaciousMappings(Configuration nhConfiguration)
{
ModelMapper mapper = new ModelMapper();
mapper.AddMappings(typeof(OrderSagaDataLoquacious).Assembly.GetTypes());
nhConfiguration.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
return nhConfiguration;
}
示例5: ComponentMappingJustOnceDemo
public void ComponentMappingJustOnceDemo()
{
var mapper = new ModelMapper();
mapper.Component<Name>(comp =>
{
comp.Property(name => name.First);
comp.Property(name => name.Last);
});
mapper.Component<Address>(comp =>
{
comp.Property(address => address.CivicNumber);
comp.Property(address => address.Street);
});
mapper.Class<Person1>(cm =>
{
cm.Id(person => person.Id, map => map.Generator(Generators.HighLow));
cm.Property(person => person.Test);
cm.Component(person => person.Name, comp => { });
cm.Component(person => person.Address, comp => { });
});
var hbmMapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
var hbmClass = hbmMapping.RootClasses[0];
var hbmComponents = hbmClass.Properties.OfType<HbmComponent>();
hbmComponents.Should().Have.Count.EqualTo(2);
hbmComponents.Select(x => x.Name).Should().Have.SameValuesAs("Name","Address");
}
示例6: GetMappings
protected override HbmMapping GetMappings()
{
var mapper = new ModelMapper();
mapper.Class<Parent>(rc =>
{
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
rc.Property(x => x.Name);
rc.List(x => x.Children,
m =>
{
m.Lazy(CollectionLazy.Extra);
m.Cascade(Mapping.ByCode.Cascade.All | Mapping.ByCode.Cascade.DeleteOrphans);
m.Inverse(true);
},
relation => relation.OneToMany());
});
mapper.Class<Child>(rc =>
{
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
rc.Property(x => x.Name);
rc.ManyToOne(x => x.Parent);
});
return mapper.CompileMappingForAllExplicitlyAddedEntities();
}
示例7: AzureSubcriptionStorage
/// <summary>
/// Configures the storage with the user supplied persistence configuration
/// Azure tables are created if requested by the user
/// </summary>
/// <param name="config"></param>
/// <param name="connectionString"></param>
/// <param name="createSchema"></param>
/// <returns></returns>
public static Configure AzureSubcriptionStorage(this Configure config,
string connectionString,
bool createSchema,
string tableName)
{
var cfg = new Configuration()
.DataBaseIntegration(x =>
{
x.ConnectionString = connectionString;
x.ConnectionProvider<TableStorageConnectionProvider>();
x.Dialect<TableStorageDialect>();
x.Driver<TableStorageDriver>();
});
SubscriptionMap.TableName = tableName;
var mapper = new ModelMapper();
mapper.AddMappings(Assembly.GetExecutingAssembly().GetExportedTypes());
var faultMappings = mapper.CompileMappingForAllExplicitlyAddedEntities();
cfg.AddMapping(faultMappings);
if (createSchema)
{
new SchemaExport(cfg).Execute(true, true, false);
}
var sessionSource = new SubscriptionStorageSessionProvider(cfg.BuildSessionFactory());
config.Configurer.RegisterSingleton<ISubscriptionStorageSessionProvider>(sessionSource);
config.Configurer.ConfigureComponent<SubscriptionStorage>(DependencyLifecycle.InstancePerCall);
return config;
}
示例8: BuildConfiguration
public static Configuration BuildConfiguration(string connStr)
{
var cfg = new Configuration();
// See http://fabiomaulo.blogspot.com/2009/07/nhibernate-configuration-through.html
cfg.DataBaseIntegration(db => {
db.Driver<SqlClientDriver>();
db.Dialect<MsSql2012Dialect>();
db.ConnectionString = connStr; // db.ConnectionStringName = "ConnStr";
db.HqlToSqlSubstitutions = "true 1, false 0, yes 'Y', no 'N'";
// See http://geekswithblogs.net/lszk/archive/2011/07/12/showing-a-sql-generated-by-nhibernate-on-the-vs-build-in.aspx
//db.LogSqlInConsole = true; // Remove if using Log4Net
//db.LogFormattedSql = true;
//db.AutoCommentSql = true;
db.SchemaAction = SchemaAutoAction.Validate; // This correspond to "hbm2ddl.validate", see http://nhforge.org/blogs/nhibernate/archive/2008/11/23/nhibernate-hbm2ddl.aspx
});
var mapper = new ModelMapper();
mapper.Class<Parent>(map => {
map.Id(x => x.Id, m => {
m.Generator(Generators.GuidComb);
m.UnsavedValue(Guid.Empty);
});
map.Version(x => x.RowVersion, m => m.UnsavedValue(0));
map.Property(x => x.Description);
});
cfg.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
return cfg;
}
示例9: 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();
}
示例10: GetMappings
protected override HbmMapping GetMappings()
{
var mapper = new ModelMapper();
mapper.BeforeMapClass += (inspector, type, map) => map.Id(x=> x.Generator(Generators.GuidComb));
mapper.Class<Foo>(mc =>
{
mc.Id(x => x.Id);
mc.Bag(x => x.Bars, map =>
{
map.Inverse(true);
map.Cascade(Mapping.ByCode.Cascade.All);
map.Key(km =>
{
km.Column("FooId");
km.OnDelete(OnDeleteAction.Cascade);
});
}, rel => rel.OneToMany());
});
mapper.Class<Bar>(mc =>
{
mc.Id(x => x.Id);
mc.ManyToOne(x=> x.Foo, map=> map.Column("FooId"));
});
var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities();
return mappings;
}
示例11: 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);
}
示例12: CriarSchema
public void CriarSchema()
{
// Apenas no Init da Aplicação
var config = new Configuration();
config.DataBaseIntegration(c =>
{
c.Dialect<MsSql2012Dialect>();
c.ConnectionStringName = "ExemploNH";
c.LogFormattedSql = true;
c.LogSqlInConsole = true;
c.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
});
var modelMapper = new ModelMapper();
modelMapper.AddMappings(typeof (ProdutoMap).Assembly.GetExportedTypes());
config.AddDeserializedMapping(modelMapper.CompileMappingForAllExplicitlyAddedEntities(), "Domain");
ISessionFactory sessionFactory = config.BuildSessionFactory();
// NOTE: Estudar framework FluentMigration
var schemaExport = new SchemaExport(config);
schemaExport.Create(true, true);
}
示例13: InitializeSessionFactory
private static void InitializeSessionFactory()
{
if (sessionFactory == null)
{
lock (mutex)
{
if (sessionFactory == null)
{
configuration = new Configuration();
configuration.DataBaseIntegration(db =>
{
db.ConnectionString = connectionString;
db.Dialect<MsSql2008Dialect>();
db.Driver<SqlClientDriver>();
db.Timeout = 20;
db.LogFormattedSql = Config.LogSql;
db.LogSqlInConsole = Config.LogSql;
});
var modelMapper = new ModelMapper();
modelMapper.AddMappings(ExportedTypes);
var mappingDocument = modelMapper.CompileMappingForAllExplicitlyAddedEntities();
configuration.AddMapping(mappingDocument);
sessionFactory = configuration.BuildSessionFactory();
}
}
}
}
示例14: GetMappings
protected override HbmMapping GetMappings()
{
var mapper = new ModelMapper();
mapper.Class<Author>(rc =>
{
rc.Id(x => x.Id, m => m.Generator(Generators.Identity));
rc.Property(x => x.Name);
rc.ManyToOne(x => x.Publisher, m => m.Cascade(Mapping.ByCode.Cascade.All));
rc.Set(x => x.Books, m =>
{
m.Cascade(Mapping.ByCode.Cascade.All);
m.Lazy(CollectionLazy.Lazy);
}, r => r.OneToMany());
});
mapper.Class<Book>(rc =>
{
rc.Id(x => x.Id, m => m.Generator(Generators.Identity));
rc.Property(x => x.Title);
rc.ManyToOne(x => x.Author);
});
mapper.Class<Publisher>(rc =>
{
rc.Id(x => x.Id, m => m.Generator(Generators.Identity));
rc.Property(x => x.Name);
rc.Set(x => x.Authors, m => m.Cascade(Mapping.ByCode.Cascade.All), r => r.OneToMany());
});
return mapper.CompileMappingForAllExplicitlyAddedEntities();
}
示例15: GetMappings
private HbmMapping GetMappings()
{
var mapper = new ModelMapper();
mapper.Class<User>(rt =>
{
rt.Id(x => x.Id, map => map.Generator(Generators.Guid));
rt.Property(x => x.Name);
rt.Set(x => x.Roles, map =>
{
map.Table("UsersToRoles");
map.Inverse(true);
map.Key(km => km.Column("UserId"));
}, rel => rel.ManyToMany(mm =>
{
mm.Column("RoleId");
mm.ForeignKey("FK_RoleInUser");
}));
});
mapper.Class<Role>(rt =>
{
rt.Id(x => x.Id, map => map.Generator(Generators.Guid));
rt.Property(x => x.Name);
rt.Set(x => x.Users, map =>
{
map.Table("UsersToRoles");
map.Key(km => km.Column("RoleId"));
}, rel => rel.ManyToMany(mm =>
{
mm.Column("UserId");
mm.ForeignKey("FK_UserInRole");
}));
});
var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities();
return mappings;
}