本文整理汇总了C#中NHibernate.Mapping.ByCode.ConventionModelMapper.IsEntity方法的典型用法代码示例。如果您正苦于以下问题:C# ConventionModelMapper.IsEntity方法的具体用法?C# ConventionModelMapper.IsEntity怎么用?C# ConventionModelMapper.IsEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NHibernate.Mapping.ByCode.ConventionModelMapper
的用法示例。
在下文中一共展示了ConventionModelMapper.IsEntity方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DefineBaseClass
private static void DefineBaseClass(ConventionModelMapper mapper, System.Type[] baseEntityToIgnore)
{
if (baseEntityToIgnore == null) return;
mapper.IsEntity((type, declared) =>
baseEntityToIgnore.Any(x => x.IsAssignableFrom(type)) &&
!baseEntityToIgnore.Any(x => x == type) &&
!type.IsInterface);
mapper.IsRootEntity((type, declared) => baseEntityToIgnore.Any(x => x == type.BaseType));
}
示例2: AddConventionalMapping
static void AddConventionalMapping(Configuration cfg)
{
var modelMapper = new ConventionModelMapper();
modelMapper.IsEntity((x, y) => x.IsClass == true && x.IsSealed == false && x.Namespace == typeof(Program).Namespace);
modelMapper.BeforeMapClass += (x, y, z) => { z.Id(a => a.Generator(Generators.Identity)); z.Lazy(true); };
modelMapper.BeforeMapManyToOne += (x, y, z) => { z.Lazy(LazyRelation.Proxy); z.NotNullable(true); };
var mappings = modelMapper.CompileMappingFor(typeof(Program).Assembly.GetTypes().Where(x => x.IsPublic && x.IsSealed == false));
cfg.AddMapping(mappings);
}
示例3: GetMappings
protected override HbmMapping GetMappings()
{
var mapper = new ConventionModelMapper();
System.Type baseEntityType = typeof (DomainObject);
mapper.IsEntity((t, declared) => baseEntityType.IsAssignableFrom(t) && !baseEntityType.Equals(t));
mapper.IsRootEntity((t, declared) => baseEntityType.Equals(t.BaseType));
mapper.Class<DomainObject>(r =>
{
r.Version(x => x.EntityVersion, map => { });
r.Id(x => x.ID, map => map.Generator(Generators.Native));
});
mapper.Class<Class1>(r => { r.IdBag(x => x.Class2List, map => map.Inverse(true), rel => rel.ManyToMany()); });
mapper.Class<Class2>(r => { r.IdBag<Class1>("_class1List", map => { }, rel => rel.ManyToMany()); });
HbmMapping mappings = mapper.CompileMappingFor(new[] {typeof (Class1), typeof (Class2)});
return mappings;
}
示例4: WhenPropertyVersionFromBaseEntityThenFindItAsVersion
public void WhenPropertyVersionFromBaseEntityThenFindItAsVersion()
{
var mapper = new ConventionModelMapper();
var baseEntityType = typeof(BaseEntity);
mapper.IsEntity((t, declared) => baseEntityType.IsAssignableFrom(t) && baseEntityType != t && !t.IsInterface);
mapper.IsRootEntity((t, declared) => baseEntityType.Equals(t.BaseType));
mapper.Class<BaseEntity>(
map =>
{
map.Id(x => x.Id, idmap => { });
map.Version(x => x.Version, vm => { });
});
var hbmMapping = mapper.CompileMappingFor(new[] { typeof(Person) });
var hbmClass = hbmMapping.RootClasses[0];
var hbmVersion = hbmClass.Version;
Assert.That(hbmVersion, Is.Not.Null);
Assert.That(hbmVersion.name, Is.EqualTo("Version"));
}
示例5: CreateMappingConfiguration
public static HbmMapping CreateMappingConfiguration()
{
var mapper = new ConventionModelMapper();
var baseEntityType = typeof (Entity);
mapper.IsEntity((t, declared) => baseEntityType.IsAssignableFrom(t) && baseEntityType != t && !t.IsInterface);
mapper.IsRootEntity((t, declared) => baseEntityType.Equals(t.BaseType));
mapper.BeforeMapManyToOne += (insp, prop, map) => map.Column(prop.LocalMember.GetPropertyOrFieldType().Name + "Id");
mapper.BeforeMapBag += (insp, prop, map) => map.Key(km => km.Column(prop.GetContainerEntity(insp).Name + "Id"));
mapper.BeforeMapBag += (insp, prop, map) => map.Cascade(Cascade.All);
mapper.Class<Album>(map => map.Id(x => x.AlbumId, m=> m.Generator(Generators.Identity)));
mapper.Class<Artist>(map => map.Id(x => x.ArtistId, m => m.Generator(Generators.Identity)));
var mapping = mapper.CompileMappingFor(baseEntityType.Assembly.GetExportedTypes());
return mapping;
}
示例6: Create
public ISessionFactory Create()
{
var cfg = new Configuration();
cfg.DataBaseIntegration(
db =>
{
db.ConnectionString =
"Server=tcp:localhost;Database=DataSample;Trusted_Connection=true;Encrypt=False;";
db.Dialect<MsSql2008Dialect>();
db.BatchSize = 250;
db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
db.SchemaAction = SchemaAutoAction.Update;
}).SessionFactory().GenerateStatistics();
var mapper = new ConventionModelMapper();
// filter entities
var baseEntityType = typeof(AbstractEntity);
mapper.IsEntity(
(t, declared) => baseEntityType.IsAssignableFrom(t) && baseEntityType != t && !t.IsInterface);
mapper.IsRootEntity((t, declared) => baseEntityType.Equals(t.BaseType));
// override base properties
mapper.Class<AbstractEntity>(
map =>
{
map.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
});
mapper.BeforeMapProperty += OnBeforeMapProperty;
// compile
var mapping =
mapper.CompileMappingFor(
typeof(AbstractEntity).Assembly.GetExportedTypes().Where(type => typeof(AbstractEntity).IsAssignableFrom(type)));
// use mappings
cfg.AddMapping(mapping);
// build
return cfg.BuildSessionFactory();
}
示例7: WhenVersionFromBaseEntityThenShouldntMapVersionAsProperty
public void WhenVersionFromBaseEntityThenShouldntMapVersionAsProperty()
{
var mapper = new ConventionModelMapper();
var baseEntityType = typeof(BaseEntity);
mapper.IsEntity((t, declared) => baseEntityType.IsAssignableFrom(t) && baseEntityType != t && !t.IsInterface);
mapper.IsRootEntity((t, declared) => baseEntityType == t.BaseType);
mapper.Class<BaseEntity>(
map =>
{
map.Id(x => x.Id, idmap => { });
map.Version(x => x.Version, vm => { });
});
var hbmMapping = mapper.CompileMappingFor(new[] { typeof(Person) });
var hbmClass = hbmMapping.RootClasses[0];
var hbmVersion = hbmClass.Version;
Assert.That(hbmVersion, Is.Not.Null);
Assert.That(hbmVersion.name, Is.EqualTo("Version"));
Assert.That(hbmClass.Properties, Is.Empty, "because one is the POID and the other is the version");
}
示例8: Configure
public void Configure(Configuration configuration)
{
var mapper = new ConventionModelMapper();
var baseEntityType = typeof (Entity);
mapper.IsEntity((t, declared) => baseEntityType.IsAssignableFrom(t) && baseEntityType != t && !t.IsInterface);
mapper.IsRootEntity((t, declared) => baseEntityType.Equals(t.BaseType));
mapper.BeforeMapManyToOne += (insp, prop, map) => map.Column(prop.LocalMember.GetPropertyOrFieldType().Name + "Id");
mapper.BeforeMapBag += (insp, prop, map) => map.Key(km => km.Column(prop.GetContainerEntity(insp).Name + "Id"));
mapper.BeforeMapBag += (insp, prop, map) => map.Cascade(Cascade.All);
mapper.Class<Entity>(map =>
{
map.Id(x => x.Id, m => m.Generator(Generators.GuidComb));
map.Version(x => x.Version, m => m.Generated(VersionGeneration.Never));
});
var mapping = mapper.CompileMappingFor(baseEntityType.Assembly.GetExportedTypes());
configuration.AddDeserializedMapping(mapping, "Cronos");
}
示例9: Generate
public static HbmMapping Generate()
{
//Conventions
var mapper = new ConventionModelMapper();
var baseEntity = typeof (EntityBase);
mapper.BeforeMapProperty += (ispector, member, customizer) => customizer.Length(40);
mapper.BeforeMapManyToOne +=
(insp, prop, map) => map.Column(prop.LocalMember.GetPropertyOrFieldType().Name + "Id");
mapper.BeforeMapManyToOne +=
(insp, prop, map) => map.Cascade(Cascade.Persist);
mapper.BeforeMapBag +=
(insp, prop, map) => map.Key(km => km.Column(prop.GetContainerEntity(insp).Name + "Id"));
mapper.BeforeMapSet +=
(insp, prop, map) => map.Key(km => km.Column(prop.GetContainerEntity(insp).Name + "Id"));
mapper.IsEntity((t, d) => baseEntity.IsAssignableFrom(t) && baseEntity != t);
mapper.IsRootEntity((t, d) => t.BaseType == baseEntity);
mapper.IsSet(IsSetFieldType);
Customize(mapper);
HbmMapping mappings = mapper.CompileMappingFor(new[]
{
typeof (Customization), typeof (Order),
typeof (Payment),
typeof (OrderItem), typeof (Product)
});
return mappings;
}
示例10: ExcludeBaseEntity
public static void ExcludeBaseEntity(ConventionModelMapper modelMapper, Type baseEntityType)
{
modelMapper.IsEntity((t, declared) => baseEntityType.IsAssignableFrom(t) && baseEntityType != t && !t.IsInterface);
modelMapper.IsRootEntity((type, declared) => type.BaseType != null && type.BaseType.Equals(baseEntityType));
}