private bool ProcessUniqueKeyAttribute(IManyToOneInstance instance) { if (instance.Property.MemberInfo.IsDefined(typeof(KeyAttribute), false)) { instance.Index($"IX_{instance.Name}_{instance.EntityType.Name}"); return(true); } else { var uniqueAttribute = (from attribute in instance.Property.MemberInfo.GetCustomAttributes(typeof(UniqueAttribute), false) select(UniqueAttribute) attribute).FirstOrDefault(); if (uniqueAttribute != null) { if (!string.IsNullOrWhiteSpace(uniqueAttribute.KeyName)) { instance.UniqueKey(uniqueAttribute.KeyName); } else { instance.UniqueKey($"UQ_{instance.Name}_{instance.EntityType.Name}"); } return(true); } } return(false); }
public void Apply(IManyToOneInstance instance) { var entityName = NameConverter.ConvertName(instance.EntityType.Name); var columnName = NameConverter.ConvertName(instance.Name); var keyName = string.Format("fk_{0}_{1}", columnName, entityName); instance.ForeignKey(keyName); instance.Column(string.Format(CultureInfo.InvariantCulture, "{0}_id", columnName)); instance.Index(string.Format(CultureInfo.InvariantCulture, "ix_{0}_{1}_id", entityName, columnName)); }
public void Apply(IManyToOneInstance instance) { var attribute = instance.Property.MemberInfo.GetCustomAttribute <IndexAttribute>(); if (attribute == null) { return; } instance.Index(attribute.IsKeySet ? GetIndexName(instance.EntityType.Name, attribute.KeyName) : GetIndexName(instance.EntityType.Name, instance.Name)); }
/// <summary> /// Applies Index based on type. /// </summary> /// <param name="instance">The instance.</param> public void Apply(IManyToOneInstance instance) { var isUniqeIndexCreated = CreateUniqeIndexIfIndicated(instance.Property, instance.Unique, instance.UniqueKey); if (!isUniqeIndexCreated) { var referenceName = instance.GetReferenceName().Replace("`1", string.Empty); var indexKeyName = string.Format("{0}_FK_IDX", referenceName); instance.Index(indexKeyName); } }
public void Apply(IManyToOneInstance instance) { instance.Cascade.SaveUpdate(); instance.NotFound.Ignore(); instance.ForeignKey(string.Format("FK_{0}_{1}", (instance.EntityType != null) ? instance.EntityType.Name : instance.Name, instance.Property.Name)); var index = string.Format("IX_{0}_{1}", instance.EntityType.Name, instance.Property.Name); if (Indices.Contains(index)) return; instance.Index(index); Indices.Add(index); }
/// <inheritdoc /> public void Apply([NotNull] IManyToOneInstance instance) { Fail.IfArgumentNull(instance, nameof(instance)); Fail.IfArgumentNull(instance.EntityType, nameof(instance.EntityType)); Fail.IfArgumentNull(instance.Class, nameof(instance.Class)); Fail.IfArgumentNull(instance.Property, nameof(instance.Property)); var columnName = ForeignKeyColumnNameConvention.GetColumnName(instance.Property); var tableWithColumnName = $"{instance.EntityType.Name}_{columnName}"; string fk = $"FK_{tableWithColumnName}_{instance.Class.Name}"; // TODO:mace (from:mace on:26-11-2016) call IndexNamingConvention below string ix = $"IX_{tableWithColumnName}"; instance.ForeignKey(fk); instance.Index(ix); }
public void Apply(IManyToOneInstance instance) { instance.Cascade.SaveUpdate(); instance.NotFound.Ignore(); instance.ForeignKey(string.Format("FK_{0}_{1}", (instance.EntityType != null) ? instance.EntityType.Name : instance.Name, instance.Property.Name)); var index = string.Format("IX_{0}_{1}", instance.EntityType.Name, instance.Property.Name); if (Indices.Contains(index)) { return; } instance.Index(index); Indices.Add(index); }
/// <summary> /// Applies Index based on type. /// </summary> /// <param name="instance">The instance.</param> public void Apply( IManyToOneInstance instance ) { var isUniqeIndexCreated = CreateUniqeIndexIfIndicated ( instance.Property, instance.Unique, instance.UniqueKey ); if ( !isUniqeIndexCreated ) { var referenceName = instance.GetReferenceName ().Replace ( "`1", string.Empty ); var indexKeyName = string.Format ( "{0}_FK_IDX", referenceName ); instance.Index ( indexKeyName ); } }
public void Apply(IManyToOneInstance instance) { instance.ForeignKey($"FK_{instance.EntityType.Name}_{instance.Name}"); instance.Index($"IDX_{instance.EntityType.Name}_{instance.Property.Name}"); }