本文整理汇总了C#中Mapper.AddCollectionPattern方法的典型用法代码示例。如果您正苦于以下问题:C# Mapper.AddCollectionPattern方法的具体用法?C# Mapper.AddCollectionPattern怎么用?C# Mapper.AddCollectionPattern使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mapper
的用法示例。
在下文中一共展示了Mapper.AddCollectionPattern方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddCustomDelegatedApplierWithMember
public void AddCustomDelegatedApplierWithMember()
{
var orm = new Mock<IDomainInspector>();
var mapper = new Mapper(orm.Object);
var previousCollectionApplierCount = mapper.PatternsAppliers.Collection.Count;
mapper.AddCollectionPattern(mi => true, (mi, cm) => cm.BatchSize(25));
mapper.PatternsAppliers.Collection.Count.Should().Be(previousCollectionApplierCount + 1);
}
示例2: 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));
}
示例3: Act
private HbmMapping Act(Mock<IDomainInspector> orm)
{
var mapper = new Mapper(orm.Object);
mapper.AddCollectionPattern(mi => true, cm => cm.BatchSize(25));
return mapper.CompileMappingFor(new[] { typeof(MyClass) });
}