public void Apply(IOneToManyCollectionInstance instance) { instance.Key.Column(string.Format(CultureInfo.InvariantCulture, "{0}_id", NameConverter.ConvertName(instance.EntityType.Name))); instance.Key.ForeignKey(string.Format(CultureInfo.InvariantCulture, "fk_{0}_{1}", NameConverter.ConvertName(instance.Member.Name), NameConverter.ConvertName(instance.EntityType.Name))); }
/// <summary> /// Apply changes to the target /// </summary> public void Apply(IOneToManyCollectionInstance instance) { instance.Key.ForeignKey(String.Format("FK_{0}_{1}", instance.ChildType.Name, instance.EntityType.Name)); instance.Key.Column(instance.EntityType.Name + "ID"); instance.Cascade.AllDeleteOrphan(); instance.Inverse(); }
public void Apply(IOneToManyCollectionInstance instance) { var originName = ConventionsUtilities .CamelCaseToUpperCaseWithUnderscoreSeparator(instance.EntityType.Name); instance.Key.Column(originName + "_ID"); }
public void Apply(IOneToManyCollectionInstance instance) { instance.Key.Column(instance.EntityType.Name + "Id"); instance.Inverse(); instance.Access.CamelCaseField(); instance.Cascade.AllDeleteOrphan(); }
public void Apply(IOneToManyCollectionInstance instance) { instance.Key.Column(instance.EntityType.Name + "Id"); instance.Key.ForeignKey(instance.EntityType.Name + "_" + instance.ChildType.Name + "_FK"); instance.Cascade.AllDeleteOrphan(); instance.Inverse(); }
/// <inheritdoc /> public void Apply(IOneToManyCollectionInstance instance) { // TODO: Change to readonly if write-behind 2nd level caching becomes possible instance.Cache.IncludeAll(); instance.Cache.ReadWrite(); instance.Cache.Region(RegionName); }
public void Apply(IOneToManyCollectionInstance instance) { instance.LazyLoad(); instance.AsBag(); instance.Cascade.AllDeleteOrphan(); instance.Inverse(); }
public void Apply(IOneToManyCollectionInstance instance) { instance.Access.CamelCaseField(CamelCasePrefix.Underscore); instance.Access.ReadOnlyPropertyThroughCamelCaseField(CamelCasePrefix.Underscore); instance.Cascade.All(); instance.Inverse(); }
public virtual void Apply(IOneToManyCollectionInstance instance) { instance.Cascade.None(); instance.Inverse(); instance.Key.Column("id" + instance.Member.DeclaringType.Name); instance.LazyLoad(); }
public void Apply(IOneToManyCollectionInstance instance) { if (instance.TableName != null) { instance.Table(AlterTableName(instance.TableName)); } }
public void Apply(IOneToManyCollectionInstance instance) { if (instance.ChildType.IsSubclassOf(typeof(TenantEntity))) { instance.ApplyFilter<TenantFilter>("tenantid = :tid"); } }
public void Apply(IOneToManyCollectionInstance instance) { instance.LazyLoad(); instance.AsBag(); instance.Cascade.SaveUpdate(); instance.Inverse(); }
public virtual void Apply(IOneToManyCollectionInstance instance) { var fk = instance.Member.GetCustomAttribute(typeof(ForeignKeyAttribute)) as ForeignKeyAttribute; instance.Key.Column(fk != null ? fk.Name : string.Format("{0}{1}", instance.EntityType.Name, "Id")); instance.LazyLoad(); }
public void Apply(IOneToManyCollectionInstance instance) { var abbreviation = AttributeHelper.GetTypeAttribute<AbbreviationAttribute>(instance.EntityType); var prefix = abbreviation == null ? instance.EntityType.Name : abbreviation.Abbreviation; instance.Key.Column((prefix + "Id").EscapeColumnName()); }
public void Apply(IOneToManyCollectionInstance instance) { //foreach (var column in instance.Key.Columns.OfType<ColumnInstance>()) { // column.Set(x => x.Name, Layer.Defaults, column.Name.ToCamelCase()); //} instance.Key.Column(string.Format("[{0}_id]", instance.Member.Name.ToCamelCase())); //instance.Key.Column(string.Format("[{0}_revision]", instance.Member.Name.ToCamelCase())); }
public void Apply(IOneToManyCollectionInstance instance) { // looks for a Property which references the type containing the collection var referenceProperty = instance.ChildType.GetProperties() .First(prop => prop.PropertyType == instance.EntityType); instance.Key.Column(referenceProperty.Name + "Id"); }
public void Apply(IOneToManyCollectionInstance instance) { string entity = instance.EntityType.Name; string member = instance.Member.Name; string child = instance.ChildType.Name; instance.Key.ForeignKey(string.Format("FK_{0}{1}_{2}", entity, member, child)); }
public void Apply(IOneToManyCollectionInstance instance) { instance.AsSet(); instance.Inverse(); instance.Where("StatusType!=-1"); instance.Cascade.AllDeleteOrphan(); instance.Generic(); }
public void Apply(IOneToManyCollectionInstance instance) { instance.Key.Column(instance.EntityType.Name + "Fk"); instance.BatchSize(5); instance.Cascade.All(); }
public void Apply(IOneToManyCollectionInstance instance) { string entity = instance.EntityType.Name; string member = instance.Member.Name; string child = instance.ChildType.Name; instance.Key.ForeignKey($"FK_{entity}{member}_{child}"); }
public void Apply(IOneToManyCollectionInstance instance) { var abbreviation = AttributeHelper.GetTypeAttribute <AbbreviationAttribute>(instance.EntityType); var prefix = abbreviation == null ? instance.EntityType.Name : abbreviation.Abbreviation; instance.Key.Column((prefix + "Id").EscapeColumnName()); }
public void Apply(IOneToManyCollectionInstance instance) { var originName = ConventionsUtilities .CamelCaseToUpperCaseWithUnderscoreSeparator(instance.Member.Name); var targetName = ConventionsUtilities .CamelCaseToUpperCaseWithUnderscoreSeparator(instance.EntityType.Name); instance.Key.ForeignKey(String.Format("FK_{0}_{1}", originName, targetName)); }
public void Apply(IOneToManyCollectionInstance instance) { var tableName = GetTableName(instance); instance.AsSet(); instance.Table(tableName); instance.CollectionType<PersistentMultiCultureStringType>(); instance.Cascade.AllDeleteOrphan(); }
public void Apply(IOneToManyCollectionInstance instance) { if (instance.TableName.IsNotNull()) { instance.Table( string.Format("`{0}_{1}`", Prefix, instance.TableName.Replace("`", "")) ); } }
public void Apply(IOneToManyCollectionInstance instance) { instance.Key.ForeignKey( string.Format( CultureInfo.InvariantCulture, FluentConfiguration.ForeignKeyTemplate, instance.EntityType.Name, Inflector.Pluralize(instance.Member.Name))); }
/// <summary> /// one to many /// </summary> /// <remarks>HasMany Map</remarks> public void Apply(IOneToManyCollectionInstance instance) { instance.Key.ForeignKey(GetForeignKeyName(instance.ChildType.Name, instance.EntityType.Name)); instance.KeyNullable(); instance.KeyUpdate(); instance.Cache.ReadWrite(); instance.Cache.Region(instance.EntityType.Name); }
public void Apply(IOneToManyCollectionInstance instance) { var type = instance.Member.GetUnderlyingType(); if (!typeof(IDictionary).IsAssignableFrom(type) && !type.IsAssignableToGenericType(typeof(IDictionary <,>))) //Map must have inverse set to false { instance.Inverse(); } //var inverseAttribute = instance.ChildType.GetCustomAttribute<InverseAttribute>(); var inverseAttribute = instance.Member.GetCustomAttribute <InverseAttribute>(); if (instance.EntityType.IsAssignableToGenericType(typeof(Document <, , ,>))) { var mapping = GetMapping(instance.Key.Columns.First()); mapping.Set(x => x.Name, Layer.UserSupplied, "ParentId"); } if (inverseAttribute != null) { switch (inverseAttribute.Type) { case InverseAttribute.CascadeType.None: instance.Cascade.None(); break; case InverseAttribute.CascadeType.All: instance.Cascade.All(); break; case InverseAttribute.CascadeType.AllDeleteOrphan: instance.Cascade.AllDeleteOrphan(); break; case InverseAttribute.CascadeType.Delete: instance.Cascade.Delete(); break; case InverseAttribute.CascadeType.Merge: instance.Cascade.Merge(); break; case InverseAttribute.CascadeType.SaveUpdate: instance.Cascade.SaveUpdate(); break; case InverseAttribute.CascadeType.DeleteOrphan: instance.Cascade.DeleteOrphan(); break; } } else { instance.Cascade.AllDeleteOrphan(); } }
public void Apply(IOneToManyCollectionInstance instance) { var type = GetUnderlyingType(instance.Member); if (!typeof(IDictionary).IsAssignableFrom(type) && !IsAssignableToGenericType(type, (typeof(IDictionary <,>)))) //Map must have inverse set to false { instance.Inverse(); } instance.Cascade.AllDeleteOrphan(); }
public void Apply(IOneToManyCollectionInstance instance) { instance.Key.Column(instance.EntityType.Name + "Id"); var parent = instance.Relationship.EntityType.Name.Pluralize(); instance.Key.ForeignKey( $"FK_{instance.StringIdentifierForModel.Pluralize()}_For_{parent}"); instance.Cascade.AllDeleteOrphan(); instance.Inverse(); }
public void Apply(IOneToManyCollectionInstance instance) { instance.LazyLoad(); instance.BatchSize(5); instance.Access.CamelCaseField(CamelCasePrefix.Underscore); instance.Cascade.All(); instance.Key.Column(Inflector.Underscore(instance.EntityType.Name) + "_id"); instance.Key.ForeignKey(string.Format("fk_{0}_{1}", NamingHelper.GetPrefixedName(instance.EntityType), Inflector.Underscore(instance.ChildType.Name).ToLower())); }
/// <summary> /// Applies this has many convention to the specified <see cref = "IOneToManyCollectionInstance" />. /// </summary> /// <param name="instance">An <see cref = "IOneToManyCollectionInstance" />.</param> public void Apply(IOneToManyCollectionInstance instance) { if (instance == null) { throw new ArgumentNullException("instance"); } instance.Key.Column(instance.EntityType.Name + "Id"); instance.Cascade.AllDeleteOrphan(); instance.Inverse(); }
public void Apply(IOneToManyCollectionInstance instance) { instance.Cache.ReadWrite(); instance.Cascade.SaveUpdate(); instance.Cascade.AllDeleteOrphan(); instance.Fetch.Subselect(); instance.Inverse(); instance.Relationship.NotFound.Ignore(); instance.Key.ForeignKey(string.Format("FK_{0}_{1}", instance.ChildType.Name, instance.EntityType.Name)); instance.Where("(IsDeleted = 'False' or IsDeleted = 0 or IsDeleted is null)"); }
public void Apply(IOneToManyCollectionInstance instance) { instance.Key.Column(instance.EntityType.Name.ToDatabaseName() + "_ID"); instance.Cascade.AllDeleteOrphan(); //instance.Inverse(); if (typeof (IPermanent).IsAssignableFrom(instance.ChildType)) { instance.ApplyFilter<IsDeletedFilter>("IS_DELETED = :DeleteFlag"); } Debug.WriteLine("----HasManyConvention----"+instance.EntityType.Name.ToDatabaseName() + "_ID" + instance.EntityType.ToString()+" "+instance.ChildType.ToString()); }
public void Apply(IOneToManyCollectionInstance instance) { instance.Key.Column(instance.EntityType.Name.ToDatabaseName() + "_ID"); instance.Cascade.AllDeleteOrphan(); //instance.Inverse(); if (typeof(IPermanent).IsAssignableFrom(instance.ChildType)) { instance.ApplyFilter <IsDeletedFilter>("IS_DELETED = :DeleteFlag"); } Debug.WriteLine("----HasManyConvention----" + instance.EntityType.Name.ToDatabaseName() + "_ID" + instance.EntityType.ToString() + " " + instance.ChildType.ToString()); }
public void Apply(IOneToManyCollectionInstance instance) { var prop = instance.Member as PropertyInfo; if (prop != null && prop.PropertyType.Closes(typeof(IList <>))) { instance.AsList(); instance.Key.Column(instance.Relationship.EntityType.Name + "Id"); instance.Index.Column("Ordinal"); } instance.Cascade.AllDeleteOrphan(); }
public void Apply(IOneToManyCollectionInstance instance) { try { instance.Key.ForeignKey( string.Format("FK_{0}_{1}_{2}", instance.Relationship.Class.Name.CleanBaseClassName(), instance.EntityType.Name.CleanBaseClassName(), instance.Key.Columns.First().Name.Trim('[', ']')).Trim('_')); } catch { } }
public void Apply(IOneToManyCollectionInstance instance) { instance.Cascade.AllDeleteOrphan(); var propertyName = instance.Member.Name; var parentType = instance.Member.DeclaringType; var parentCollectionProperty = parentType.GetInstanceProperties().FirstOrDefault(x => x.Name == propertyName); if (parentCollectionProperty == null) { return; } var parentCollectionPropertyBackingFieldName = _propertyNameToBackingFieldNameFunc?.Invoke(propertyName) ?? "_" + Char.ToLower(propertyName[0]) + propertyName.Substring(1); var parentCollectionPropertyBackingField = parentType.GetInstanceFields().FirstOrDefault(x => x.Name == parentCollectionPropertyBackingFieldName); if (parentCollectionPropertyBackingField != null) { instance.Access.ReadOnlyPropertyThroughCamelCaseField(CamelCasePrefix.Underscore); _setInverseAndAsSet(parentCollectionPropertyBackingField.PropertyType); } else { _setInverseAndAsSet(parentCollectionProperty.PropertyType); } void _setInverseAndAsSet(Type collectionType) { if (collectionType.IsSubclassOfRawGeneric(typeof(IList <>))) { return; } if (_doesChildReferenceTheParent()) { instance.Inverse(); } instance.AsSet(); } bool _doesChildReferenceTheParent() { #if NET40 var childType = parentCollectionProperty.PropertyType.GetGenericArguments()[0]; #else var childType = parentCollectionProperty.PropertyType.GenericTypeArguments[0]; #endif var parentPropertyInChildType = childType.GetInstanceProperties().FirstOrDefault(x => x.PropertyType == parentType); return(parentPropertyInChildType != null); } }
public void Apply(IOneToManyCollectionInstance instance) { _collectionCascadeInstanceAction?.Invoke(instance.Cascade); var propertyName = instance.Member.Name; var parentType = instance.Member.DeclaringType; var parentCollectionProperty = parentType.GetInstanceProperties().FirstOrDefault(x => x.Name == propertyName); if (parentCollectionProperty == null) { return; } var parentCollectionPropertyBackingFieldName = _getBackingFieldNameFromPropertyName(propertyName); var parentCollectionPropertyBackingField = parentType.GetInstanceFields().FirstOrDefault(x => x.Name == parentCollectionPropertyBackingFieldName); if (parentCollectionPropertyBackingField != null) { _setCollectionInstanceAccess(instance.Access); _markAsInverseIfPossibleAndSetAsSetOrAsList(parentCollectionPropertyBackingField.PropertyType); } else { _markAsInverseIfPossibleAndSetAsSetOrAsList(parentCollectionProperty.PropertyType); } void _markAsInverseIfPossibleAndSetAsSetOrAsList(Type collectionType) { if (collectionType.IsSubclassOfRawGeneric(typeof(IList <>))) { instance.AsList(); return; } if (_doesChildReferenceTheParent()) { instance.Inverse(); } instance.AsSet(); } bool _doesChildReferenceTheParent() { #if NET40 var childType = parentCollectionProperty.PropertyType.GetGenericArguments()[0]; #else var childType = parentCollectionProperty.PropertyType.GenericTypeArguments[0]; #endif var parentPropertyInChildType = childType.GetInstanceProperties().FirstOrDefault(x => x.PropertyType == parentType); return(parentPropertyInChildType != null); } }
public void Apply(IOneToManyCollectionInstance instance) { if (instance == null) { return; } instance.Key.ForeignKey($"FK_{instance.Member.Name}_{instance.EntityType.Name}"); if (instance.Member.IsDefined(typeof(RequiredAttribute), false)) { instance.Not.KeyNullable(); } }
public void Apply(IOneToManyCollectionInstance instance) { var mappingfield = instance.Key.Columns.First().GetType() .GetField("mapping", BindingFlags.Instance | BindingFlags.NonPublic); var columnMapping = (ColumnMapping)mappingfield.GetValue(instance.Key.Columns.First()); if (!columnMapping.HasValue(c => c.Index)) { var typename = instance.Member.DeclaringType.Name; columnMapping.Index = string.Format("index_{0}_{1}", typename.ToLower(), instance.Member.Name.ToLower()); } }
public void Apply(IOneToManyCollectionInstance instance) { instance.Access.ReadOnlyPropertyThroughCamelCaseField(CamelCasePrefix.Underscore); instance.Cascade.AllDeleteOrphan(); if (instance.OtherSide == null) instance.Not.Inverse(); else instance.Inverse(); instance.BatchSize(500); instance.AsSet(); instance.Not.KeyNullable(); instance.LazyLoad(); }
/// <summary> /// Applies Key based on type. /// </summary> /// <param name="instance">The instance.</param> public void Apply(IOneToManyCollectionInstance instance) { var entityType = instance.EntityType; // name the key field var key = entityType.Name; if (typeof(ILookup).IsAssignableFrom(entityType)) { key = key + "Lkp"; } instance.Key.Column(key + "Key"); instance.Inverse(); }
/// <summary> /// Sets cascade mode to AllDeleteOrphan for all types except Aggregate roots. /// Aggregate roots cascade mode is None. /// </summary> /// <param name="instance">The instance.</param> public void Apply( IOneToManyCollectionInstance instance ) { var rootSubclass = typeof( AbstractAggregateRoot ).IsAssignableFrom ( instance.Relationship.Class.GetUnderlyingSystemType () ); if ( rootSubclass ) { instance.Cascade.None (); } else { instance.Cascade.AllDeleteOrphan (); } }
/// <summary> /// Applies access based on type. /// </summary> /// <param name="instance">The instance.</param> public void Apply( IOneToManyCollectionInstance instance ) { var entityType = instance.EntityType; var propertyName = instance.Member.Name; var propertyInfo = entityType.GetProperty ( propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance ); if ( propertyInfo.IsAutoProperty () ) { instance.Access.BackField (); } else { instance.Access.CamelCaseField ( CamelCasePrefix.Underscore ); } }
public void Apply(IOneToManyCollectionInstance instance) { instance.Access.ReadOnlyPropertyThroughCamelCaseField(); instance.Cascade.AllDeleteOrphan(); instance.AsSet(); instance.BatchSize(25); if (instance.OtherSide == null) { instance.Not.Inverse(); } else { instance.Inverse(); } instance.Not.KeyNullable(); }
public void Apply(IOneToManyCollectionInstance instance) { instance.ApplyFilter<DeletedFilter>(); instance.Key.Column(instance.EntityType.Name + "Fk"); //demonstrate business requirement - all has many relation should be fethced eagerly //to alleviate classic N+1 problem when iterating an "entity list property" and //access properties on each iterator item //set batch 5 to eager fetch at most 5 entities when accessing a collection property. //its a good candidate for a general purpose query performance tuning //Note: the global class level adonet.batch_size can be set in nhibernate.config file instance.BatchSize(5); instance.Cascade.All(); }
public void Apply(IOneToManyCollectionInstance instance) { instance.Cascade.AllDeleteOrphan(); var propertyName = instance.Member.Name; var declaringType = instance.Member.DeclaringType; var property = declaringType.GetInstanceProperties().FirstOrDefault(x => x.Name == propertyName); if (property == null) return; var backingFieldName = "_" + Char.ToLower(propertyName[0]) + propertyName.Substring(1); var field = declaringType.GetInstanceFields().FirstOrDefault(x => x.Name == backingFieldName); if (field != null) { instance.Access.ReadOnlyPropertyThroughCamelCaseField(CamelCasePrefix.Underscore); SetInverseAndAsSetIfNotAList(field.PropertyType, instance); } else { SetInverseAndAsSetIfNotAList(property.PropertyType, instance); } }
public void Apply(IOneToManyCollectionInstance instance) { instance.Fetch.Select(); instance.Cache.ReadWrite(); }
public void Apply(IOneToManyCollectionInstance instance) { DefaultCascade.All(); }
public void Apply(IOneToManyCollectionInstance instance) { instance.Key.ForeignKey(string.Format("{0}_{1}_FK", instance.Member.Name, instance.EntityType.Name)); }
public void Apply(IOneToManyCollectionInstance instance) { instance.Cascade.AllDeleteOrphan(); }
public void Apply(IOneToManyCollectionInstance instance) { instance.Fetch.Select(); }
public void Apply(IOneToManyCollectionInstance instance) { instance.Key.Column("test_column"); instance.Key.ForeignKey("test_fk"); }