本文整理汇总了C#中AutoPersistenceModel.AddEntityAssembly方法的典型用法代码示例。如果您正苦于以下问题:C# AutoPersistenceModel.AddEntityAssembly方法的具体用法?C# AutoPersistenceModel.AddEntityAssembly怎么用?C# AutoPersistenceModel.AddEntityAssembly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AutoPersistenceModel
的用法示例。
在下文中一共展示了AutoPersistenceModel.AddEntityAssembly方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SagaPersistenceModel
public static AutoPersistenceModel SagaPersistenceModel(IEnumerable<Type> typesToScan)
{
var sagaEntites = typesToScan.Where(t => typeof(ISagaEntity).IsAssignableFrom(t) && !t.IsInterface);
var model = new AutoPersistenceModel();
model.Conventions.AddFromAssemblyOf<IdShouldBeAssignedConvention>();
var entityTypes = GetTypesThatShouldBeAutoMapped(sagaEntites,typesToScan);
var assembliesContainingSagas = sagaEntites.Select(t => t.Assembly).Distinct();
foreach (var assembly in assembliesContainingSagas)
model.AddEntityAssembly(assembly)
.Where(t => entityTypes.Contains(t));
var componentTypes = GetTypesThatShouldBeMappedAsComponents(sagaEntites);
model.Setup(s =>
{
s.IsComponentType =
type => componentTypes.Contains(type);
});
return model;
}
示例2: Generate
public AutoPersistenceModel Generate()
{
var mappings = new AutoPersistenceModel();
mappings.AddEntityAssembly(typeof (Class1).Assembly).Where(GetAutoMappingFilter);
mappings.Conventions.Setup(GetConventions());
mappings.Setup(GetSetup());
mappings.UseOverridesFromAssemblyOf<AutoPersistenceModelGenerator>();
return mappings;
}
示例3: Generate
public AutoPersistenceModel Generate()
{
var mappings = new AutoPersistenceModel();
mappings.AddEntityAssembly(typeof(Soul).Assembly).Where(GetAutoMappingFilter);
mappings.Conventions.Setup(GetConventions());
mappings.Setup(GetSetup());
mappings.IgnoreBase<Entity>();
mappings.IgnoreBase(typeof(EntityWithTypedId<>));
mappings.UseOverridesFromAssemblyOf<AutoPersistenceModelGenerator>();
// Membershipprovider Automappings
mappings.AddEntityAssembly(typeof(Shaml.Membership.Core.User).Assembly).Where(GetAutoMappingFilter);
mappings.Override<Shaml.Membership.Core.User>(map => Shaml.Membership.Data.Overrides.UserOverride(map));
mappings.Override<Shaml.Membership.Core.Role>(map => Shaml.Membership.Data.Overrides.RoleOverride(map));
mappings.Override<Shaml.Membership.Core.ProfileData>(map => Shaml.Membership.Data.Overrides.ProfileDataOverride(map));
mappings.Override<Shaml.Membership.Core.Session>(map => Shaml.Membership.Data.Overrides.SessionOverride(map));
return mappings;
}
示例4: Generate
public AutoPersistenceModel Generate()
{
var mappings = new AutoPersistenceModel();
mappings.AddEntityAssembly(typeof(Site).Assembly).Where(GetAutoMappingFilter);
// mappings.Setup(GetSetup());
mappings.IgnoreBase<Entity>();
mappings.IgnoreBase(typeof(EntityWithTypedId<>));
mappings.UseOverridesFromAssemblyOf<AutoPersistenceModelGenerator>();
return mappings;
}
示例5: Generate
public AutoPersistenceModel Generate()
{
var mappings = new AutoPersistenceModel();
mappings.AddEntityAssembly(typeof (Class1).Assembly).Where(GetAutoMappingFilter);
mappings.Conventions.Setup(GetConventions());
mappings.Setup(GetSetup());
mappings.UseOverridesFromAssemblyOf<AutoPersistenceModelGenerator>();
mappings.Override<Idea>(i => i.Map(m => m.Text).CustomSqlType("TEXT"));
mappings.Override<Comment>(c => c.Map(m => m.Text).CustomSqlType("TEXT"));
return mappings;
}
示例6: Generate
public AutoPersistenceModel Generate()
{
var mappings = new AutoPersistenceModel();
mappings
.AddEntityAssembly(typeof(Player).Assembly)
.UseOverridesFromAssembly(typeof(AutoPersistenceModelGenerator).Assembly)
.Where(GetAutoMappingFilter);
//.Setup(GetSetup())
//.Conventions.Setup(GetConventions);
MapEnums(mappings);
return mappings;
}
示例7: GetAutoMappingSettings
private static AutoPersistenceModel GetAutoMappingSettings( Assembly entitiesAssembly, Assembly mappingsOverridesAssembly )
{
var persistenceModel = new AutoPersistenceModel();
persistenceModel.AddEntityAssembly( entitiesAssembly ).Where( x => x.BaseType.Name == "BaseEntity" );
persistenceModel.UseOverridesFromAssembly( mappingsOverridesAssembly );
persistenceModel.Conventions.Add(
PrimaryKey.Name.Is( x => "Id" ),
ConventionBuilder.Id.Always( x => x.GeneratedBy.Identity() ),
ConventionBuilder.Property.Always( x => x.Not.Nullable() ),
ConventionBuilder.Property.When( expectation =>
expectation.Expect( propertyInspector => propertyInspector.Property.PropertyType == typeof( string ) ),
instance => instance.Length( 256 ) ),
ConventionBuilder.Reference.Always( x => x.Not.Nullable() ),
ForeignKey.EndsWith( "Id" )
);
return persistenceModel;
}
示例8: GetSessionFactory
ISessionFactory GetSessionFactory()
{
var autoPersistenceModel = new AutoPersistenceModel();
autoPersistenceModel
.AddEntityAssembly(GetType().Assembly)
.Where(t => t.Namespace.StartsWith("NHibernateWebPersistenceExample.Models"));
ISessionFactory sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(c =>
c.Is(
@"Data Source=.\SQLEXPRESS;Initial Catalog=Example;Integrated Security=True;Pooling=False"))
.ShowSql())
.Mappings(m => m.AutoMappings.Add(autoPersistenceModel))
.ExposeConfiguration(innerConfiguration =>
innerConfiguration.SetProperty("current_session_context_class", "web"))
.BuildSessionFactory();
return sessionFactory;
}
示例9: AutoMap
/// <summary>
/// Configures FluentNHibernate to map the domain types used in PerfTest.
/// </summary>
public static AutoPersistenceModel AutoMap(AutoPersistenceModel model)
{
model
.AddEntityAssembly(typeof(TestSuiteResult).Assembly)
.Override<TestSuiteResult>(map =>
{
map.HasMany(x => x.SystemInfoList).AsSet().Inverse().Cascade.All().Not.LazyLoad();
map.HasMany(x => x.TestResultList).AsSet().Inverse().Cascade.All().Not.LazyLoad();
})
.Override<SystemInfo>(map =>
{
map.References(x => x.TestSuiteResult, "TestSuiteResultId").Cascade.None().Not.Nullable();
})
.Override<TestResult>(map =>
{
map.HasMany(x => x.TimingDataList).AsSet().Inverse().Cascade.All().Not.LazyLoad();
map.References(x => x.TestSuiteResult, "TestSuiteResultID").Cascade.None().Not.Nullable();
})
.Override<TimingData>(map =>
{
map.References(x => x.TestResult, "TestResultID").Cascade.None().Not.Nullable();
});
return model;
}
示例10: SetupAutoMapperForEntities
public static void SetupAutoMapperForEntities(IDependencyResolver dependencyResolver, params Assembly[] assemblies)
{
var database = dependencyResolver.Resolve<IPersistenceConfigurer>();
var config = Fluently.Configure().Database(database);
var stringPropertyconvention = ConventionBuilder.Property.When(x => x.Expect(p => p.Property.PropertyType == typeof (string)), a => a.Length(255));
var cacheConvention = ConventionBuilder.Class.Always(c => c.Cache.ReadWrite());
var collectionsConventionMany = ConventionBuilder.HasMany.When(
x => x.Expect(p => !(p.Member is DummyPropertyInfo)),
instance => { instance.Cascade.SaveUpdate(); instance.Cache.ReadWrite(); });
var collectionsConventionManyToMany = ConventionBuilder.HasManyToMany.When(
x => x.Expect(p => !(p.Member is DummyPropertyInfo)),
instance => { instance.Cascade.SaveUpdate(); instance.Cache.ReadWrite(); });
var lazyConvention = ConventionBuilder.Reference.Always(c => c.LazyLoad());
IEnumerable<Assembly> ass;
if (assemblies == null || assemblies.Length == 0)
{
ass = AppDomain.CurrentDomain.GetAssemblies().Where(
a => !a.FullName.StartsWith("System.") &&
!a.FullName.StartsWith("Microsoft.") &&
!a.FullName.Contains("mscorlib") &&
a != typeof(ISession).Assembly &&
a != typeof(AutoMap).Assembly
);
}
else
{
ass = assemblies;
}
var autoPersistenceModel = new AutoPersistenceModel()
.Conventions.Add(cacheConvention, collectionsConventionMany, collectionsConventionManyToMany, stringPropertyconvention, lazyConvention)
.IgnoreBase(typeof (BaseEntity<>))
.IgnoreBase(typeof (IBaseEntity));
foreach (var assembly in ass)
{
try
{
assembly.GetExportedTypes();
}
catch (NotSupportedException)
{
continue;//cannot do dynamic assemblies
}
if (assembly != null)
{
Assembly automapper = assembly;
config.Mappings(m => m.HbmMappings.AddFromAssembly(automapper));
autoPersistenceModel
.AddEntityAssembly(automapper)
.Conventions.AddAssembly(automapper)
.Alterations(alterations => alterations.AddFromAssembly(automapper))
.Alterations(collection => collection.Add(new AutoMappingOverrideAlteration(automapper))) //same as: UseOverridesFromAssemblyOf<Tentity>()
.Where(t => typeof (IBaseEntity).IsAssignableFrom(t));
// MORE Evil hack, since adding to the Alterations does NOT work.
//new AutoMappingOverrideAlteration(automapper).Alter(autoPersistenceModel);
}
}
// Evil hack, since adding to the Alterations does NOT work.
//foreach (var overrideAssembly in ass)
//{
// new AutoMappingOverrideAlteration(overrideAssembly).Alter(autoPersistenceModel);
//}
config.Mappings(m => m.AutoMappings.Add(autoPersistenceModel)
#if DEBUG
.ExportTo(@"C:\temp\")
#endif
);
var nhconfig = config.BuildConfiguration();
var sessionFactory = config.BuildSessionFactory();
dependencyResolver.RegisterInstance<Configuration>(nhconfig);
dependencyResolver.RegisterInstance<ISessionFactory>(sessionFactory);
new SchemaUpdate(nhconfig).Execute(true, true);
}
示例11: RegisterEntitiesAssembly
private void RegisterEntitiesAssembly(Configuration configuration, Assembly assembly)
{
var model = new AutoPersistenceModel()
.WithSetup(s => s.IsBaseType = (type => type == typeof (BaseEntity) || type == typeof (BaseOrderedEntity)
|| type == typeof (BaseVersionedEntity) || type == typeof (BaseVersionedAndOrderedEntity)))
.ConventionDiscovery.Setup(c =>
{
c.Add<FluentNHibernate.Conventions.Defaults.PrimaryKeyConvention>();
c.Add<ForeignKeyConvention>();
c.Add<TableNameConvention>();
c.Add<ManyToManyTableConvention>();
}
);
model
.AddEntityAssembly(assembly)
.Where(entity => entity.IsAbstract == false &&
entity.GetInterface("IEntity") != null)
.Configure(configuration);
}