本文整理汇总了C#中Mapper.AddPropertyPattern方法的典型用法代码示例。如果您正苦于以下问题:C# Mapper.AddPropertyPattern方法的具体用法?C# Mapper.AddPropertyPattern怎么用?C# Mapper.AddPropertyPattern使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mapper
的用法示例。
在下文中一共展示了Mapper.AddPropertyPattern方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMapping
private static HbmMapping GetMapping()
{
var orm = new ObjectRelationalMapper();
var mapper = new Mapper(orm,
new CoolPatternsAppliersHolder(orm));
orm.TablePerClassHierarchy<Product>();
orm.TablePerClass<ActorRole>();
orm.Patterns.PoidStrategies.Add(
new GuidOptimizedPoidPattern());
orm.VersionProperty<Entity>(x => x.Version);
orm.NaturalId<Product>(p => p.Name);
orm.Cascade<Movie, ActorRole>(
Cascade.All | Cascade.DeleteOrphans);
mapper.AddPropertyPattern(mi =>
mi.GetPropertyOrFieldType() == typeof(Decimal) &&
mi.Name.Contains("Price"),
pm => pm.Type(NHibernateUtil.Currency));
mapper.AddPropertyPattern(mi =>
orm.IsRootEntity(mi.DeclaringType) &&
!"Description".Equals(mi.Name),
pm => pm.NotNullable(true));
mapper.Subclass<Movie>(cm =>
cm.List(movie => movie.Actors,
colm => colm.Index(
lim => lim.Column("ActorIndex")), m => { }));
var domainClasses = typeof(Entity).Assembly.GetTypes()
.Where(t => typeof(Entity).IsAssignableFrom(t));
return mapper.CompileMappingFor(domainClasses);
}
示例2: InitMappings
/// <summary>
/// Initializes the mappings.
/// </summary>
/// <param name="config">The configuration.</param>
public static void InitMappings(Configuration config)
{
var orm = new ObjectRelationalMapper();
var mapper = new Mapper(orm);
mapper.AddPropertyPattern(mi => mi.GetPropertyOrFieldType() == typeof(string) && !mi.Name.EndsWith("Text"), pm => pm.Length(50));
mapper.AddPropertyPattern(mi => mi.GetPropertyOrFieldType() == typeof(string) && mi.Name.EndsWith("Text"), pm => pm.Type(NHibernateUtil.StringClob));
orm.Patterns.PoidStrategies.Add(new AssignedPoidPattern());
foreach (var componentDbInit in IoC.ResolveAllInstances<IComponentDbInit>())
{
componentDbInit.InitMappings(orm, mapper);
}
// compile the mapping for the specified entities
HbmMapping mappingDocument = mapper.CompileMappingFor(ListOfModelTypes());
// inject the mapping in NHibernate
config.AddDeserializedMapping(mappingDocument, "Domain");
// fix up the schema
SchemaMetadataUpdater.QuoteTableAndColumns(config);
SessionFactory.SessionFactoryInstance = config.BuildSessionFactory();
}
示例3: ExecuteCustomDelegatedApplier
public void ExecuteCustomDelegatedApplier()
{
var orm = new Mock<IDomainInspector>();
orm.Setup(m => m.IsEntity(It.IsAny<Type>())).Returns(true);
orm.Setup(m => m.IsRootEntity(It.IsAny<Type>())).Returns(true);
orm.Setup(m => m.IsTablePerClass(It.IsAny<Type>())).Returns(true);
orm.Setup(m => m.IsPersistentId(It.Is<MemberInfo>(mi => mi.Name == "Id"))).Returns(true);
orm.Setup(m => m.IsPersistentProperty(It.Is<MemberInfo>(mi => mi.Name != "Id"))).Returns(true);
var mapper = new Mapper(orm.Object);
mapper.AddPropertyPattern(mi => mi.GetPropertyOrFieldType() == typeof(DateTime) && (mi.Name.StartsWith("Date") || mi.Name.EndsWith("Date")),
pm => pm.Type(NHibernateUtil.Date));
var mapping = mapper.CompileMappingFor(new[] {typeof (MyClass)});
var hbmClass = mapping.RootClasses.Single();
var hbmProp = (HbmProperty) hbmClass.Properties.First(p => p.Name == "Date");
hbmProp.Type.name.Should().Be.EqualTo("Date");
hbmProp = (HbmProperty)hbmClass.Properties.First(p => p.Name == "DateOfMeeting");
hbmProp.Type.name.Should().Be.EqualTo("Date");
hbmProp = (HbmProperty)hbmClass.Properties.First(p => p.Name == "MeetingDate");
hbmProp.Type.name.Should().Be.EqualTo("Date");
hbmProp = (HbmProperty)hbmClass.Properties.First(p => p.Name == "StartAt");
hbmProp.Type.Should().Be.Null();
}
示例4: GetMapper
private static Mapper GetMapper()
{
var orm = GetORM();
var mapper = new Mapper(orm);
mapper.AddPropertyPattern(
m => orm.IsRootEntity(m.DeclaringType) &&
!m.Name.Equals("Description"),
a => a.NotNullable(true));
return mapper;
}
示例5: AddCustomDelegatedApplier
public void AddCustomDelegatedApplier()
{
var orm = new Mock<IDomainInspector>();
var mapper = new Mapper(orm.Object);
var previousPropertyApplierCount = mapper.PatternsAppliers.Property.Count;
mapper.AddPropertyPattern(mi => mi.Name.StartsWith("Date") || mi.Name.EndsWith("Date"),
pm => pm.Type(NHibernateUtil.Date));
mapper.PatternsAppliers.Property.Count.Should().Be(previousPropertyApplierCount + 1);
}
示例6: WhenRegisterApplierOnPropertyThenInvokeApplier
public void WhenRegisterApplierOnPropertyThenInvokeApplier()
{
Mock<IDomainInspector> orm = GetMockedDomainInspector();
var mapper = new Mapper(orm.Object);
mapper.AddPropertyPattern(mi => mi.Name == "Level", pm => pm.Column("myLevelColumn"));
HbmMapping mapping = mapper.CompileMappingFor(new[] { typeof(Person) });
var rc = mapping.RootClasses.Single();
var map = rc.Properties.OfType<HbmMap>().Single();
var hbmCompositeMapKey = (HbmCompositeMapKey)map.Item;
var hbmKeyProperty = (HbmKeyProperty)hbmCompositeMapKey.Properties.Single(p => p.Name == "Level");
hbmKeyProperty.Columns.Single().name.Should().Be("myLevelColumn");
}
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:14,代码来源:MapKeyComponentRelationAppliersCallingTest.cs
示例7: CallPatternAppliersOnNestedCompositeElements
public void CallPatternAppliersOnNestedCompositeElements()
{
Mock<IDomainInspector> orm = GetMockedDomainInspector();
var mapper = new Mapper(orm.Object);
bool reSimplePropertyCalled = false;
bool reManyToOneCalled = false;
mapper.AddPropertyPattern(mi => mi.DeclaringType == typeof(MyNestedComponent), pm => reSimplePropertyCalled = true);
mapper.AddManyToOnePattern(mi => mi.DeclaringType == typeof(MyNestedComponent), pm => reManyToOneCalled = true);
mapper.CompileMappingFor(new[] { typeof(MyClass) });
reSimplePropertyCalled.Should().Be.True();
reManyToOneCalled.Should().Be.True();
}
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:14,代码来源:AppliersCallingOnCompositeElementTest.cs
示例8: GetMapping
private static HbmMapping GetMapping()
{
var orm = new ObjectRelationalMapper();
var mapper = new Mapper(orm, new CoolPatternsAppliersHolder(orm));
mapper.AddPropertyPattern(IsLongString, p => p.Length(4001));
orm.Patterns.Poids.Add(IsId);
orm.Patterns.PoidStrategies.Add(new AssignedPoidPattern());
var domainClasses = typeof (IEntity).Assembly.GetTypes()
.Where(t => t.IsClass && !t.IsAbstract)
.Where(t => typeof (IEntity).IsAssignableFrom(t))
.ToArray();
orm.TablePerClass(domainClasses);
mapper.AddRootClassPattern(t => true, applier => applier.Lazy(false));
var mapping = mapper.CompileMappingFor(domainClasses);
return mapping;
}
示例9: ConfigureMapping
public override void ConfigureMapping(Configuration configuration)
{
var orm = new ObjectRelationalMapper();
var mapper = new Mapper(orm);
mapper.AddPropertyPattern(mi => mi.GetPropertyOrFieldType() == typeof(string), pm => pm.Length(50));
orm.Patterns.PoidStrategies.Add(new AssignedPoidPattern());
// define the mapping shape
// list all the entities we want to map.
IEnumerable<Type> baseEntities = GetMappingTypes();
// we map all classes as Table per class
orm.TablePerClass(baseEntities);
// compile the mapping for the specified entities
HbmMapping mappingDocument = mapper.CompileMappingFor(baseEntities);
// inject the mapping in NHibernate
configuration.AddDeserializedMapping(mappingDocument, "Domain");
SessionFactory.SessionFactoryInstance = configuration.BuildSessionFactory();
}
示例10: ConfigureMapping
public override void ConfigureMapping(NHibernate.Cfg.Configuration configuration)
{
var orm = new ObjectRelationalMapper();
var mapper = new Mapper(orm);
mapper.AddPropertyPattern(mi => TypeExtensions.GetPropertyOrFieldType(mi) == typeof(string), pm => pm.Length(50));
orm.Patterns.PoidStrategies.Add(new NativePoidPattern());
orm.Patterns.PoidStrategies.Add(new GuidOptimizedPoidPattern());
// list all the entities we want to map.
IEnumerable<Type> baseEntities = GetMappingTypes();
// we map all classes as Table per class
orm.TablePerClass(baseEntities);
mapper.Customize<Hotel>(ca => ca.Collection(item => item.Reservations, cm => cm.Key(km => km.Column("HotelId"))));
mapper.Customize<Room>(ca => ca.Collection(item => item.Reservations, cm => cm.Key(km =>
{
km.Column("RoomId");
km.OnDelete(OnDeleteAction.NoAction);
})));
mapper.Customize<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); });
});
// 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();
}
示例11: AppliesGeneralConventions
private void AppliesGeneralConventions(Mapper mapper)
{
const string softDeleteWhereClause = "DeletedOn is NULL";
// because VersionModelBase is not an entity I can use the it to customize the mapping of all inherited classes
mapper.Class<VersionModelBase>(map => map.Where(softDeleteWhereClause));
// When the collection elements inherits from VersionModelBase then should apply the where-clause for "soft delete"
mapper.AddCollectionPattern(mi => mi.GetPropertyOrFieldType().IsGenericCollection() &&
typeof (VersionModelBase).IsAssignableFrom(
mi.GetPropertyOrFieldType().DetermineCollectionElementType())
, map => map.Where(softDeleteWhereClause));
// The default length for string is 100
// Note : because this convetion has no specific restriction other than typeof(string) should be added at first (the order, in this case, is important)
mapper.AddPropertyPattern(mi => mi.GetPropertyOrFieldType() == typeof(string), map => map.Length(100));
// When the property name is Description and is of type string then apply length 500
mapper.AddPropertyPattern(mi => mi.Name == "Description" && mi.GetPropertyOrFieldType() == typeof (string),
map => map.Length(500));
// When the property is of type decimal and it refers to a price then applies Currency
mapper.AddPropertyPattern(mi => mi.Name.EndsWith("Cost") && mi.GetPropertyOrFieldType() == typeof (decimal),
map => map.Type(NHibernateUtil.Currency));
}
示例12: CustomizeColumns
private void CustomizeColumns(Mapper mapper)
{
// in EditionQuotation all references to a class inherited from Cost are not nullables (this is only an example because you can do it one by one)
mapper.AddManyToOnePattern(
mi => mi.DeclaringType == typeof (EditionQuotation) && typeof (Cost).IsAssignableFrom(mi.GetPropertyOrFieldType()),
map => map.NotNullable(true));
// in Quotation all string properties are not nullables (this is only an example because you can do it one by one)
mapper.AddPropertyPattern(
mi => mi.DeclaringType == typeof (Quotation) && mi.GetPropertyOrFieldType() == typeof (string),
map => map.NotNullable(true));
// Quotation columns size customization (if you use a Validator framework you can implements a pattern-applier to customize columns size and "nullable" stuff)
// Note: It is needed only for properties without a convention (the property Description has its convetion)
mapper.Customize<Quotation>(map =>
{
map.Property(q => q.Code, pm => pm.Length(10));
map.Property(q => q.Reference, pm => pm.Length(50));
map.Property(q => q.PaymentMethod, pm => pm.Length(50));
map.Property(q => q.TransportMethod, pm => pm.Length(50));
});
// Column customization for class ProductQuotation
// Note: It is needed only for properties outside conventions
mapper.Customize<ProductQuotation>(map => map.Property(pq => pq.Group, pm =>
{
pm.Length(50);
pm.Column("GroupName");
}));
}