本文整理汇总了C#中NHibernate.Mapping.ByCode.ConventionModelMapper.Class方法的典型用法代码示例。如果您正苦于以下问题:C# ConventionModelMapper.Class方法的具体用法?C# ConventionModelMapper.Class怎么用?C# ConventionModelMapper.Class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NHibernate.Mapping.ByCode.ConventionModelMapper
的用法示例。
在下文中一共展示了ConventionModelMapper.Class方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExplicitMapping
static void ExplicitMapping(ConventionModelMapper mapper)
{
mapper.Class<Master>(x =>
{
x.Id(y => y.Id, y => y.Generator(Generators.HighLow));
x.Set(y => y.Options, y =>
{
y.Key(z => z.Column("master_id"));
y.Table("master_option");
}, y =>
{
y.ManyToMany(z =>
{
z.Column("option_id");
});
});
});
mapper.Class<Option>(x =>
{
x.Id(y => y.Id, y => y.Generator(Generators.HighLow));
x.Set(y => y.Masters, y =>
{
y.Key(z => z.Column("option_id"));
y.Table("master_option");
y.Inverse(true);
}, y =>
{
y.ManyToMany(z =>
{
z.Column("master_id");
});
});
});
}
示例2: TestFixtureSetUp
public void TestFixtureSetUp()
{
configuration = new Configuration();
configuration.SessionFactory()
.Integrate.Using<SQLiteDialect>()
.Connected.Using("Data source=testdb")
.AutoQuoteKeywords()
.LogSqlInConsole()
.EnableLogFormattedSql();
var mapper = new ConventionModelMapper();
mapper.Class<Foo>(cm => { });
mapper.Class<Bar>(cm => { });
CustomizeMapping(mapper);
var mappingDocument = mapper.CompileMappingForAllExplicitlyAddedEntities();
new XmlSerializer(typeof(HbmMapping)).Serialize(Console.Out, mappingDocument);
configuration.AddDeserializedMapping(mappingDocument, "Mappings");
new SchemaExport(configuration).Create(true, true);
sessionFactory = configuration.BuildSessionFactory();
using (var session = sessionFactory.OpenSession())
using (var tx = session.BeginTransaction())
{
var foo = new Foo { Bars = CreateCollection() };
foo.Bars.Add(new Bar { Data = 1 });
foo.Bars.Add(new Bar { Data = 2 });
id = session.Save(foo);
tx.Commit();
}
sessionFactory.Statistics.IsStatisticsEnabled = true;
}
示例3: 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;
}
示例4: 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;
}
示例5: Main
static void Main(string[] args)
{
SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
var mapper = new ConventionModelMapper();
mapper.Class<SomeAreaClass>(c =>
{
c.Property(x => x.Area, m =>
{
m.Type<MsSql2008GeographyType>();
m.NotNullable(true);
});
});
var cfg = new Configuration()
.DataBaseIntegration(db =>
{
db.ConnectionString = "YourConnectionString";
db.Dialect<MsSql2012GeographyDialect>();
});
cfg
.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
cfg
.AddAuxiliaryDatabaseObject(new SpatialAuxiliaryDatabaseObject(cfg));
new SchemaExport(cfg).Execute(false, true, false);
}
示例6: CustomizeMapping
protected override void CustomizeMapping(ConventionModelMapper mapper)
{
mapper.Class<Foo>(cm => cm.List(x => x.Bars, bpm =>
{
bpm.Cascade(Cascade.All);
bpm.Type<PersistentQueryableListType<Bar>>();
}));
}
示例7: 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");
}
示例8: CustomizeMapping
protected override void CustomizeMapping(ConventionModelMapper mapper)
{
mapper.Class<Foo>(cm => cm.IdBag(x => x.Bars,
bpm =>
{
bpm.Cascade(Cascade.All);
bpm.Type<PersistentQueryableIdBagType<Bar>>();
},
cer => cer.ManyToMany()));
}
示例9: 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");
}
示例10: 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;
}
示例11: 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());
}
示例12: 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");
}
示例13: 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;
Assert.That(hbmId, Is.Not.Null);
Assert.That(hbmId.generator, Is.Not.Null);
Assert.That([email protected], Is.EqualTo("guid"));
Assert.That(hbmId.type1, Is.EqualTo("Guid"));
}
示例14: ConfigureMapping
public override void ConfigureMapping(NHibernate.Cfg.Configuration configuration)
{
var mapper = new ConventionModelMapper();
mapper.BeforeMapProperty += (inspector, member, customizer) =>
{
if (member.LocalMember.GetPropertyOrFieldType() == typeof(string))
{
customizer.Length(50);
}
};
mapper.BeforeMapClass += (inspector, type, customizer) => customizer.Id(im => im.Generator(Generators.GuidComb));
// define the mapping shape
mapper.Class<Hotel>(ca => ca.List(item => item.Reservations, cm => cm.Key(km => km.Column("HotelId"))));
mapper.Class<Room>(ca => ca.List(item => item.Reservations, cm => cm.Key(km =>
{
km.Column("RoomId");
km.OnDelete(OnDeleteAction.NoAction);
})));
mapper.Class<Reservation>(ca =>
{
ca.ManyToOne(item => item.Hotel, m => { m.Column("HotelId"); m.Insert(false); m.Update(false); m.Lazy(LazyRelation.Proxy);} );
ca.ManyToOne(item => item.Room, m => { m.Column("RoomId"); m.Insert(false); m.Update(false); m.Lazy(LazyRelation.Proxy); });
});
// list all the entities we want to map.
IEnumerable<Type> baseEntities = GetMappingTypes();
// compile the mapping for the specified entities
HbmMapping mappingDocument = mapper.CompileMappingFor(baseEntities);
// inject the mapping in NHibernate
configuration.AddDeserializedMapping(mappingDocument, "Domain");
// fix up the schema
SchemaMetadataUpdater.QuoteTableAndColumns(configuration);
SessionFactory.SessionFactoryInstance = configuration.BuildSessionFactory();
}
示例15: GetMappingWithParentInCompo
private HbmMapping GetMappingWithParentInCompo()
{
var mapper = new ConventionModelMapper();
mapper.Class<MyClass>(x =>
{
x.Id(c => c.Id);
x.Component(c => c.Compo);
});
mapper.Component<MyCompo>(x =>
{
x.Property(c => c.Something);
});
return mapper.CompileMappingForAllExplicitlyAddedEntities();
}