本文整理汇总了C#中IModelInspector类的典型用法代码示例。如果您正苦于以下问题:C# IModelInspector类的具体用法?C# IModelInspector怎么用?C# IModelInspector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IModelInspector类属于命名空间,在下文中一共展示了IModelInspector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeforeMappingCollectionConvention
private void BeforeMappingCollectionConvention(IModelInspector inspector, PropertyPath member, ICollectionPropertiesMapper customizer)
{
if (inspector.IsManyToMany(member.LocalMember))
customizer.Table(member.ManyToManyIntermediateTableName());
customizer.Key(k => k.Column(DetermineKeyColumnName(inspector, member)));
}
示例2: MemberReadOnlyAccessor
protected virtual void MemberReadOnlyAccessor(IModelInspector modelInspector, PropertyPath member, IAccessorPropertyMapper propertyCustomizer)
{
if (MatchReadOnlyProperty(member.LocalMember))
{
propertyCustomizer.Access(Accessor.ReadOnly);
}
}
示例3: MapStringLengthFromAttribute
public static void MapStringLengthFromAttribute(IModelInspector modelinspector, PropertyPath member, IPropertyMapper propertycustomizer)
{
var propertyInfo = member.LocalMember as PropertyInfo;
if (propertyInfo == null || propertyInfo.PropertyType != typeof(string))
{
return;
}
var attributes = propertyInfo.GetCustomAttributes(true);
var attribute = attributes.FirstOrDefault(x => x.GetType().Name.IndexOf("Length") > -1);
if (attribute == null)
{
return;
}
int value = 0;
var possiblePropertyNames = new[] { "MaximumLength", "Length", "Max", "MaxLength" };
foreach (var name in possiblePropertyNames)
{
var attributeProperty = attribute.GetType().GetProperty(name);
if (attributeProperty != null)
{
value = (int)attributeProperty.GetValue(attribute, null);
break;
}
}
if (value == 0)
{
throw new InvalidOperationException(
string.Format("could not get the length of property {0}", propertyInfo.Name));
}
propertycustomizer.Length(value);
}
示例4: OnBeforeMapProperty
private void OnBeforeMapProperty(IModelInspector modelinspector, PropertyPath member, IPropertyMapper propertycustomizer)
{
if(member.LocalMember.Name == "Name")
{
propertycustomizer.Unique(true);
}
}
示例5: ManyToManyConvention
public static void ManyToManyConvention(IModelInspector modelInspector, PropertyPath member, IManyToManyMapper map)
{
map.ForeignKey(
string.Format("fk_{0}_{1}",
member.LocalMember.Name,
member.GetContainerEntity(modelInspector).Name));
}
示例6: DetermineKeyColumnName
private static string DetermineKeyColumnName(IModelInspector inspector, PropertyPath member)
{
var otherSideProperty = member.OneToManyOtherSideProperty();
if (inspector.IsOneToMany(member.LocalMember) && otherSideProperty != null)
return otherSideProperty.Name + ForeignKeyColumnPostfix;
return member.Owner().Name + ForeignKeyColumnPostfix;
}
示例7: MapStringAsVarchar
public static void MapStringAsVarchar(IModelInspector modelInspector, PropertyPath member, IPropertyMapper propertyCustomizer)
{
var propertyInfo = member.LocalMember as PropertyInfo;
if (propertyInfo != null && propertyInfo.PropertyType == typeof(string))
{
propertyCustomizer.Type(NHibernateUtil.AnsiString);
}
}
示例8: GetContainerEntity
public static System.Type GetContainerEntity(this PropertyPath propertyPath, IModelInspector domainInspector)
{
PropertyPath analizing = propertyPath;
while (analizing.PreviousPath != null && !domainInspector.IsEntity(analizing.LocalMember.ReflectedType))
{
analizing = analizing.PreviousPath;
}
return analizing.LocalMember.ReflectedType;
}
示例9: ReferenceConvention
public static void ReferenceConvention(IModelInspector modelInspector, PropertyPath member, IManyToOneMapper map)
{
map.Column(k => k.Name(member.LocalMember.GetPropertyOrFieldType().Name + "Id"));
map.ForeignKey(
string.Format("fk_{0}_{1}",
member.LocalMember.Name,
member.GetContainerEntity(modelInspector).Name));
map.Cascade(Cascade.All | Cascade.DeleteOrphans);
}
示例10: ForeignKey
/// <summary>
/// Returns the name of the foreign key in a relationship.
/// </summary>
/// <param name="inspector">The model inspector.</param>
/// <param name="member">The entity property.</param>
/// <returns>The name of the foreign key.</returns>
public string ForeignKey(IModelInspector inspector, PropertyPath member, Type declaringType = null, Type idDeclaringType = null)
{
Requires.That(member, "member").IsNotNull();
Requires.That(member.LocalMember, "member.LocalMember").IsNotNull();
return ForeignKeyNameFormat.Formatted(Table(inspector, idDeclaringType ?? member.LocalMember.GetPropertyOrFieldType()),
Table(inspector, declaringType ?? member.LocalMember.DeclaringType),
Column(inspector, member, idDeclaringType));
}
示例11: ApplyDateTimeOffsetSplitTypeToDateTimeOffset
/// <summary>
/// Applies the <see cref="DateTimeOffsetSplitType"/> Composite user type to all <see cref="DateTimeOffset"/> fields in the mapping.
/// </summary>
/// <remarks>
/// Allows the use of <see cref="DateTimeOffset"/> type with databases that do not natively support it.
/// User: mapper.BeforeMapProperty += ModelMapperHelper.ApplyDateTimeOffsetSplitTypeToDateTimeOffset
/// </remarks>
public static void ApplyDateTimeOffsetSplitTypeToDateTimeOffset(IModelInspector inspector, PropertyPath property, IPropertyMapper mapper)
{
Type propertyType = property.LocalMember.GetPropertyOrFieldType();
if (propertyType == typeof(DateTimeOffset) || propertyType == typeof(DateTimeOffset?))
{
mapper.Type(typeof(DateTimeOffsetSplitType), null);
string columName = property.ToColumnName();
mapper.Columns(n => n.Name(columName + "DateTime"), n => n.Name(columName + "Offset"));
}
}
示例12: ConventionModelMapper
private ConventionModelMapper(string tablePrefix, IModelInspector modelInspector, ICustomizersHolder customizerHolder)
: base(modelInspector, modelInspector as IModelExplicitDeclarationsHolder, customizerHolder, new DefaultCandidatePersistentMembersProvider())
{
Conventions = new MappingConventions
{
TablePrefix = tablePrefix
};
CustomizersHolder = customizerHolder;
AppendDefaultEvents();
}
示例13: OneToManyConvention
public static void OneToManyConvention(IModelInspector modelInspector, PropertyPath member, IBagPropertiesMapper map)
{
var inv = member.LocalMember.GetInverseProperty();
if (inv == null)
{
map.Key(x => x.Column(member.GetContainerEntity(modelInspector).Name + "Id"));
map.Cascade(Cascade.All | Cascade.DeleteOrphans);
map.BatchSize(20);
map.Inverse(true);
}
}
示例14: IdBagTableName
private void IdBagTableName(IModelInspector modelInspector, PropertyPath member, IIdBagPropertiesMapper propertyCustomizer)
{
if (member.LocalMember.IsComponentCollection(Mapper.ModelInspector))
{
propertyCustomizer.Table(member.GetRootMember().DeclaringType.Name + member.ToColumnName());
}
else
{
propertyCustomizer.Table(BidirectionAssociation.AnalizeManyToMany(member.LocalMember).ManyToManyTablename);
}
}
示例15: DicriminatorColumnNamedClass
private void DicriminatorColumnNamedClass(IModelInspector modelInspector, Type type, IClassAttributesMapper classCustomizer)
{
if(DiscriminatorIsNotRequired(type)) return;
classCustomizer.Discriminator(
dm =>
{
dm.Column("Class");
dm.NotNullable(true);
});
}