Add() public method

public Add ( string name ) : NameSequence
name string
return NameSequence
Esempio n. 1
0
        protected virtual FieldImplementedBy GenerateFieldImplementedBy(ITable table, PropertyRoute route, NameSequence name, bool forceNull, IEnumerable <Type> types)
        {
            Type   cleanType = Lite.Extract(route.Type) ?? route.Type;
            string errors    = types.Where(t => !cleanType.IsAssignableFrom(t)).ToString(t => t.TypeName(), ", ");

            if (errors.Length != 0)
            {
                throw new InvalidOperationException("Type {0} do not implement {1}".FormatWith(errors, cleanType));
            }

            bool nullable = Settings.IsNullable(route, forceNull) || types.Count() > 1;

            CombineStrategy strategy = Settings.FieldAttribute <CombineStrategyAttribute>(route)?.Strategy ?? CombineStrategy.Case;

            bool avoidForeignKey = Settings.FieldAttribute <AvoidForeignKeyAttribute>(route) != null;

            return(new FieldImplementedBy(route.Type)
            {
                SplitStrategy = strategy,
                ImplementationColumns = types.ToDictionary(t => t, t => new ImplementationColumn
                {
                    ReferenceTable = Include(t, route),
                    Name = name.Add(TypeLogic.GetCleanName(t)).ToString(),
                    Nullable = nullable,
                    AvoidForeignKey = avoidForeignKey,
                }),
                IsLite = route.Type.IsLite(),
                AvoidExpandOnRetrieving = Settings.FieldAttribute <AvoidExpandQueryAttribute>(route) != null
            }.Do(f => f.UniqueIndex = f.GenerateUniqueIndex(table, Settings.FieldAttribute <UniqueIndexAttribute>(route))));
        }
Esempio n. 2
0
        protected virtual FieldEmbedded GenerateFieldEmbedded(ITable table, PropertyRoute route, NameSequence name, bool forceNull, bool inMList)
        {
            bool nullable = Settings.IsNullable(route, false);

            return(new FieldEmbedded(route.Type)
            {
                HasValue = nullable ? new FieldEmbedded.EmbeddedHasValueColumn()
                {
                    Name = name.Add("HasValue").ToString()
                } : null,
                EmbeddedFields = GenerateFields(route, table, name, forceNull: nullable || forceNull, inMList: inMList)
            });
        }
Esempio n. 3
0
        protected virtual FieldImplementedByAll GenerateFieldImplementedByAll(PropertyRoute route, ITable table, NameSequence preName, bool forceNull)
        {
            bool nullable = Settings.IsNullable(route, forceNull);

            return(new FieldImplementedByAll(route.Type)
            {
                Column = new ImplementationStringColumn
                {
                    Name = preName.ToString(),
                    Nullable = nullable,
                    Size = Settings.DefaultImplementedBySize,
                },
                ColumnType = new ImplementationColumn
                {
                    Name = preName.Add("Type").ToString(),
                    Nullable = nullable,
                    ReferenceTable = Include(typeof(TypeEntity), route),
                    AvoidForeignKey = Settings.FieldAttribute <AvoidForeignKeyAttribute>(route) != null,
                },
                IsLite = route.Type.IsLite(),
                AvoidExpandOnRetrieving = Settings.FieldAttribute <AvoidExpandQueryAttribute>(route) != null
            }.Do(f => f.UniqueIndex = f.GenerateUniqueIndex(table, Settings.FieldAttribute <UniqueIndexAttribute>(route))));
        }
Esempio n. 4
0
        protected virtual Field GenerateField(ITable table, PropertyRoute route, NameSequence preName, bool forceNull, bool inMList)
        {
            KindOfField kof = GetKindOfField(route).ThrowIfNull(() => "Field {0} of type {1} has no database representation".FormatWith(route, route.Type.Name));

            if (kof == KindOfField.MList && inMList)
            {
                throw new InvalidOperationException("Field {0} of type {1} can not be nested in another MList".FormatWith(route, route.Type.TypeName(), kof));
            }

            //field name generation
            NameSequence        name;
            ColumnNameAttribute vc = Settings.FieldAttribute <ColumnNameAttribute>(route);

            if (vc != null && vc.Name.HasText())
            {
                name = NameSequence.Void.Add(vc.Name);
            }
            else if (route.PropertyRouteType != PropertyRouteType.MListItems)
            {
                name = preName.Add(GenerateFieldName(route, kof));
            }
            else if (kof == KindOfField.Enum || kof == KindOfField.Reference)
            {
                name = preName.Add(GenerateMListFieldName(route, kof));
            }
            else
            {
                name = preName;
            }

            switch (kof)
            {
            case KindOfField.PrimaryKey:
                return(GenerateFieldPrimaryKey((Table)table, route, name));

            case KindOfField.Ticks:
                return(GenerateFieldTicks((Table)table, route, name));

            case KindOfField.Value:
                return(GenerateFieldValue(table, route, name, forceNull));

            case KindOfField.Reference:
            {
                Implementations at = Settings.GetImplementations(route);
                if (at.IsByAll)
                {
                    return(GenerateFieldImplementedByAll(route, table, name, forceNull));
                }
                else if (at.Types.Only() == route.Type.CleanType())
                {
                    return(GenerateFieldReference(table, route, name, forceNull));
                }
                else
                {
                    return(GenerateFieldImplementedBy(table, route, name, forceNull, at.Types));
                }
            }

            case KindOfField.Enum:
                return(GenerateFieldEnum(table, route, name, forceNull));

            case KindOfField.Embedded:
                return(GenerateFieldEmbedded(table, route, name, forceNull, inMList));

            case KindOfField.MList:
                return(GenerateFieldMList((Table)table, route, name));

            default:
                throw new NotSupportedException(EngineMessage.NoWayOfMappingType0Found.NiceToString().FormatWith(route.Type));
            }
        }