src/Inflatable/ClassMapper/Default/ManyToOneSingle.cs
/// <summary>
/// Sets up the property (used internally)
/// </summary>
/// <param name="mappings">The mappings.</param>
/// <param name="sourceSpec">The source spec.</param>
/// <exception cref="ArgumentException">Foreign key IDs could not be found for {typeof(ClassType).Name}.{Name}</exception>
Sets up the property (used internally)
Sets up the property ( used internally )
public override void Setup(IMappingSource mappings, ISource sourceSpec)
        {
            if (mappings is null || sourceSpec is null)
                return;
            ForeignMapping = mappings.GetChildMappings<TDataType>()
                                     .SelectMany(x => mappings.GetParentMapping(x.ObjectType))
                                     .Where(x => x.IDProperties.Count > 0)
                                     .Distinct()
                                     .ToList();
            var ParentMappings = mappings.GetChildMappings(ParentMapping.ObjectType).SelectMany(x => mappings.GetParentMapping(x.ObjectType)).Distinct();
            var ActualParent = ParentMappings.FirstOrDefault(x => x.IDProperties.Count > 0);
            var ParentTable = sourceSpec.Tables.Find(x => x.Name == ActualParent.TableName);
            foreach (var TempMapping in ForeignMapping)
            {
                var SetNullOnDelete = !ParentMappings.Contains(TempMapping);
                foreach (var IDMapping in TempMapping.IDProperties)
                {
                    if (ParentTable.Columns.Any(x => x.Name == ColumnName + TempMapping.TableName + IDMapping.ColumnName))
                    {
                        continue;
                    }
                    ParentTable.AddColumn<object>(ColumnName + TempMapping.TableName + IDMapping.ColumnName,
                                    IDMapping.PropertyType.To(DbType.Int32),
                                    IDMapping.MaxLength,
                                    true,
                                    false,
                                    false,
                                    false,
                                    false,
                                    TempMapping.TableName,
                                    IDMapping.ColumnName,
                                    null!,
                                    "",
                                    false,
                                    false,
                                    !OnDeleteDoNothingValue && SetNullOnDelete);
                }
            }
        }
public override void Setup ( IMappingSource mappings , ISource sourceSpec ) { if ( mappings is null || sourceSpec is null ) return ; ForeignMapping = mappings . GetChildMappings < TDataType > ( ) . SelectMany ( x => mappings . GetParentMapping ( x . ObjectType ) ) . Where ( x => x . IDProperties . Count > 0 ) . Distinct ( ) . ToList ( ) ; var ParentMappings = mappings . GetChildMappings ( ParentMapping . ObjectType ) . SelectMany ( x => mappings . GetParentMapping ( x . ObjectType ) ) . Distinct ( ) ; var ActualParent = ParentMappings . FirstOrDefault ( x => x . IDProperties . Count > 0 ) ; var ParentTable = sourceSpec . Tables . Find ( x => x . Name == ActualParent . TableName ) ; foreach ( var TempMapping in ForeignMapping ) { var SetNullOnDelete = ! ParentMappings . Contains ( TempMapping ) ; foreach ( var IDMapping in TempMapping . IDProperties ) { if ( ParentTable . Columns . Any ( x => x . Name == ColumnName + TempMapping . TableName + IDMapping . ColumnName ) ) { continue ; } ParentTable . AddColumn < object > ( ColumnName + TempMapping . TableName + IDMapping . ColumnName , IDMapping . PropertyType . To ( DbType . Int32 ) , IDMapping . MaxLength , true , false , false , false , false , TempMapping . TableName , IDMapping . ColumnName , null ! , " " , false , false , ! OnDeleteDoNothingValue && SetNullOnDelete ) ; } } }
Sets up the property (used internally)
Sets up the property ( used internally )
Foreign key IDs could not be found for {typeof(ClassType).Name}.{Name}
Foreign key IDs could not be found for { typeof ( ClassType ) . Name } . { Name }
mappings
IMappingSource
None
sourceSpec
ISource
The source spec.
The source spec .