本文整理汇总了C#中NHibernate.Mapping.ByCode.ConventionModelMapper.CompileMappingFor方法的典型用法代码示例。如果您正苦于以下问题:C# ConventionModelMapper.CompileMappingFor方法的具体用法?C# ConventionModelMapper.CompileMappingFor怎么用?C# ConventionModelMapper.CompileMappingFor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NHibernate.Mapping.ByCode.ConventionModelMapper
的用法示例。
在下文中一共展示了ConventionModelMapper.CompileMappingFor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMappings
protected override HbmMapping GetMappings()
{
var mapper = new ConventionModelMapper();
// Working Example
//mapper.Class<Toy>(rc => rc.Set(x => x.Animals, cmap => { }, rel => rel.ManyToAny<int>(meta =>
// {
// meta.MetaValue(1, typeof (Cat));
// meta.MetaValue(2, typeof (Dog));
// })));
// User needs
mapper.Class<Toy>(rc => rc.Set(x => x.Animals, cmap =>
{
cmap.Table("Animals_Toys");
cmap.Key(km => km.Column("Cat_Id"));
}, rel => rel.ManyToAny<int>(meta =>
{
meta.MetaValue(1, typeof(Cat));
meta.MetaValue(2, typeof(Dog));
meta.Columns(cid =>
{
cid.Name("Animal_Id");
cid.NotNullable(true);
}, ctype =>
{
ctype.Name("Animal_Type");
ctype.NotNullable(true);
});
})));
var mappings = mapper.CompileMappingFor(new[] { typeof(Cat), typeof(Dog), typeof(Toy) });
//Console.WriteLine(mappings.AsString()); // <=== uncomment this line to see the XML mapping
return mappings;
}
示例2: GetIdentityMappings
/// <summary>
/// Gets a mapping that can be used with NHibernate.
/// </summary>
/// <param name="additionalTypes">Additional Types that are to be added to the mapping, this is useful for adding your ApplicationUser class</param>
/// <returns></returns>
public static HbmMapping GetIdentityMappings(System.Type[] additionalTypes)
{
var baseEntityToIgnore = new[] {
typeof(NHibernate.AspNet.Identity.DomainModel.EntityWithTypedId<int>),
typeof(NHibernate.AspNet.Identity.DomainModel.EntityWithTypedId<string>),
};
var allEntities = new List<System.Type> {
typeof(ApplicationTenant),
typeof(IdentityUser),
typeof(IdentityRole),
typeof(IdentityUserLogin),
typeof(IdentityUserClaim),
};
allEntities.AddRange(additionalTypes);
var mapper = new ConventionModelMapper();
DefineBaseClass(mapper, baseEntityToIgnore.ToArray());
mapper.IsComponent((type, declared) => typeof(NHibernate.AspNet.Identity.DomainModel.ValueObject).IsAssignableFrom(type));
mapper.AddMapping<IdentityUserMap>();
mapper.AddMapping<IdentityRoleMap>();
mapper.AddMapping<IdentityUserClaimMap>();
mapper.AddMapping<ApplicationTenantMap>();
return mapper.CompileMappingFor(allEntities);
}
示例3: Configure
public static void Configure(ISessionStorage storage)
{
var baseEntityToIgnore = new[] {
typeof(NHibernate.AspNet.Identity.DomainModel.EntityWithTypedId<int>),
typeof(NHibernate.AspNet.Identity.DomainModel.EntityWithTypedId<string>),
};
var allEntities = new[] {
typeof(IdentityUser),
typeof(ApplicationUser),
typeof(IdentityRole),
typeof(IdentityUserLogin),
typeof(IdentityUserClaim),
};
var mapper = new ConventionModelMapper();
DefineBaseClass(mapper, baseEntityToIgnore);
mapper.IsComponent((type, declared) => typeof(NHibernate.AspNet.Identity.DomainModel.ValueObject).IsAssignableFrom(type));
mapper.AddMapping<IdentityUserMap>();
mapper.AddMapping<IdentityRoleMap>();
mapper.AddMapping<IdentityUserClaimMap>();
var mapping = mapper.CompileMappingFor(allEntities);
System.Diagnostics.Debug.WriteLine(mapping.AsString());
var configuration = NHibernateSession.Init(storage, mapping);
BuildSchema(configuration);
}
示例4: NHibernateHelper
static NHibernateHelper()
{
try
{
cfg = new Configuration();
cfg.Configure("NHibernateQueryModelConfiguration.xml");
var mapper = new ConventionModelMapper();
//mapper.IsEntity((t, declared) => t.Namespace.StartsWith("Sample.QueryModel") || );
mapper.AfterMapClass += (inspector, type, classCustomizer) =>
{
classCustomizer.Lazy(false);
//classCustomizer.Id(m => m.Generator(new GuidGeneratorDef()));
};
var mapping = mapper.CompileMappingFor(
Assembly.Load("Sample.QueryModel").GetExportedTypes()
.Union(new Type[] {typeof(Version)}));
var allmapping = mapping.AsString();
cfg.AddDeserializedMapping(mapping, "AutoModel");
_sessionFactory = cfg.BuildSessionFactory();
}
catch (Exception ex)
{
throw ex;
}
}
示例5: GetIdentityMappings
/// <summary>
/// Gets a mapping that can be used with NHibernate.
/// </summary>
/// <param name="additionalTypes">Additional Types that are to be added to the mapping, this is useful for adding your ApplicationUser class</param>
/// <returns></returns>
public static HbmMapping GetIdentityMappings(System.Type[] additionalTypes)
{
var baseEntityToIgnore = new[]
{
typeof(EntityWithTypedId<int>),
typeof(EntityWithTypedId<string>)
};
// Modified for NS: PIMS.Infrastructure.NHibernate.NHAspNetIdentity
var allEntities = new List<System.Type> {
typeof(IdentityUser),
typeof(IdentityRole),
typeof(IdentityUserLogin),
typeof(IdentityUserClaim),
};
allEntities.AddRange(additionalTypes);
var mapper = new ConventionModelMapper();
DefineBaseClass(mapper, baseEntityToIgnore.ToArray());
mapper.IsComponent((type, declared) => typeof(ValueObject).IsAssignableFrom(type));
// Modified for NS: PIMS.Infrastructure.NHibernate.NHAspNetIdentity
mapper.AddMapping<IdentityUserMap>();
mapper.AddMapping<IdentityRoleMap>();
mapper.AddMapping<IdentityUserClaimMap>();
return mapper.CompileMappingFor(allEntities);
}
示例6: GetMappings
protected override HbmMapping GetMappings()
{
var mapper = new ConventionModelMapper();
mapper.IsTablePerClass((type, declared) => false);
mapper.IsTablePerClassHierarchy((type, declared) => true);
var mappings = mapper.CompileMappingFor(new[] {typeof (Animal), typeof (Reptile), typeof (Mammal), typeof (Lizard), typeof (Dog), typeof (Cat)});
return mappings;
}
示例7: WhenAutoPropertyNoAccessor
public void WhenAutoPropertyNoAccessor()
{
var mapper = new ConventionModelMapper();
var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
var hbmClass = hbmMapping.RootClasses[0];
var hbmProperty = hbmClass.Properties.Single(x => x.Name == "AProp");
hbmProperty.Access.Should().Be.NullOrEmpty();
}
示例8: WhenPoidNoSetterThenApplyNosetter
public void WhenPoidNoSetterThenApplyNosetter()
{
var mapper = new ConventionModelMapper();
mapper.Class<MyClass>(x => x.Id(mc=> mc.Id));
var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
var hbmClass = hbmMapping.RootClasses[0];
hbmClass.Id.access.Should().Be("nosetter.camelcase-underscore");
}
示例9: WhenPropertyWithSameBackFieldNoMatch
public void WhenPropertyWithSameBackFieldNoMatch()
{
var mapper = new ConventionModelMapper();
var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
var hbmClass = hbmMapping.RootClasses[0];
var hbmProperty = hbmClass.Properties.Single(x => x.Name == "SameTypeOfBackField");
hbmProperty.Access.Should().Be.NullOrEmpty();
}
示例10: WhenFieldAccessToField
public void WhenFieldAccessToField()
{
var mapper = new ConventionModelMapper();
mapper.Class<MyClass>(mc => mc.Property("aField", x => { }));
var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
var hbmClass = hbmMapping.RootClasses[0];
var hbmProperty = hbmClass.Properties.Single(x => x.Name == "aField");
hbmProperty.Access.Should().Be("field");
}
示例11: Main
static void Main(String[] args)
{
var cfg = new Configuration();
cfg.DataBaseIntegration(x =>
{
x.Dialect<MsSql2008Dialect>();
x.Driver<Sql2008ClientDriver>();
x.ConnectionString = @"Data Source=(local)\SQLEXPRESS; Initial Catalog=NHibernate; Integrated Security=SSPI";
x.SchemaAction = SchemaAutoAction.Update;
})
.SetProperty(NHibernate.Cfg.Environment.UseProxyValidator, Boolean.FalseString);
var model = new ConventionModelMapper();
model.BeforeMapClass += (a, b, c) => { c.Lazy(false); c.Id(x => x.Generator(Generators.Identity)); };
var mappings = model.CompileMappingFor(new Type[] { typeof(Xpto) });
cfg.AddMapping(mappings);
using (var sessionFactory = cfg.BuildSessionFactory())
{
var validation = sessionFactory
.FluentlyValidate()
.Entity<Xpto>(x => x.Name != "aa", "Name is empty");
using (var session = sessionFactory.OpenSession())
using (var tx = session.BeginTransaction())
{
var x = new Xpto();
try
{
session.Save(x);
session.Flush();
}
catch
{
//expected
}
x.Name = "aa";
//disable all validations
//sessionFactory.DisableFluentValidation();
//disable validations over the Xpto class
//validation.Clear<Xpto>();
//session.Save(new Xpto());
session.Flush();
//should work
}
}
}
示例12: 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);
}
示例13: WhenClassWithoutPoidWithGeneratorThenApplyDefinedGenerator
public void WhenClassWithoutPoidWithGeneratorThenApplyDefinedGenerator()
{
var mapper = new ConventionModelMapper();
mapper.Class<MyClassWithoutPoid>(x => x.Id(null, idm=> idm.Generator(Generators.Native)));
var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClassWithoutPoid) });
var hbmClass = hbmMapping.RootClasses[0];
var hbmId = hbmClass.Id;
hbmId.Should().Not.Be.Null();
hbmId.generator.Should().Not.Be.Null();
[email protected]().Be("native");
hbmId.type1.Should().Be(Generators.Native.DefaultReturnType.GetNhTypeName());
}
示例14: WhenClassWithoutPoidNorGeeneratorThenApplyGuid
public void WhenClassWithoutPoidNorGeeneratorThenApplyGuid()
{
var mapper = new ConventionModelMapper();
mapper.Class<MyClassWithoutPoid>(x => { });
var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClassWithoutPoid) });
var hbmClass = hbmMapping.RootClasses[0];
var hbmId = hbmClass.Id;
hbmId.Should().Not.Be.Null();
hbmId.generator.Should().Not.Be.Null();
[email protected]().Be("guid");
hbmId.type1.Should().Be("Guid");
}
示例15: GetMappings
protected override HbmMapping GetMappings()
{
var mapper = new ConventionModelMapper();
mapper.BeforeMapClass += (inspector, type, map) => map.Id(x => x.Generator(Generators.HighLow));
mapper.BeforeMapClass += (inspector, type, map) => map.Cache(x => x.Usage(CacheUsage.ReadWrite));
mapper.BeforeMapSet += (inspector, property, map) =>
{
map.Cascade(Mapping.ByCode.Cascade.All);
map.Cache(x => x.Usage(CacheUsage.ReadWrite));
};
var mapping = mapper.CompileMappingFor(new[] { typeof(Blog), typeof(Post), typeof(Comment) });
return mapping;
}