GetColumnsFromFields() public static method

public static GetColumnsFromFields ( ) : IColumn[]
return IColumn[]
Beispiel #1
0
        public Index AddIndex(ITable table, Field[] fields)
        {
            var index = new Index(table, Index.GetColumnsFromFields(fields));

            AddIndex(index);
            return(index);
        }
        static IColumn[] GetColumns(IFieldFinder finder, LambdaExpression field)
        {
            var body = field.Body;

            Type type = RemoveCasting(ref body);

            body = IndexWhereExpressionVisitor.RemoveLiteEntity(body);

            var members = Reflector.GetMemberListBase(body);

            if (members.Any(a => ignoreMembers.Contains(a.Name)))
            {
                members = members.Where(a => !ignoreMembers.Contains(a.Name)).ToArray();
            }

            Field f = Schema.FindField(finder, members);

            if (type != null)
            {
                var ib = f as FieldImplementedBy;
                if (ib == null)
                {
                    throw new InvalidOperationException("Casting only supported for {0}".FormatWith(typeof(FieldImplementedBy).Name));
                }

                return((from ic in ib.ImplementationColumns
                        where type.IsAssignableFrom(ic.Key)
                        select(IColumn) ic.Value).ToArray());
            }

            return(Index.GetColumnsFromFields(f));
        }
Beispiel #3
0
        public List <Index> GeneratAllIndexes()
        {
            IEnumerable <EntityField> fields = Fields.Values.AsEnumerable();

            if (Mixins != null)
            {
                fields = fields.Concat(Mixins.Values.SelectMany(m => m.Fields.Values));
            }

            var result = fields.SelectMany(f => f.Field.GenerateIndexes(this)).ToList();

            if (MultiColumnIndexes != null)
            {
                result.AddRange(MultiColumnIndexes);
            }

            if (result.OfType <UniqueIndex>().Any())
            {
                var            s = Schema.Current.Settings;
                List <IColumn> attachedFields = fields.Where(f => s.FieldAttributes(PropertyRoute.Root(this.Type).Add(f.FieldInfo)).OfType <AttachToUniqueIndexesAttribute>().Any())
                                                .SelectMany(f => Index.GetColumnsFromFields(f.Field))
                                                .ToList();

                if (attachedFields.Any())
                {
                    result = result.Select(ix =>
                    {
                        var ui = ix as UniqueIndex;
                        if (ui == null || ui.AvoidAttachToUniqueIndexes)
                        {
                            return(ix);
                        }

                        return(new UniqueIndex(ui.Table, ui.Columns.Concat(attachedFields).ToArray())
                        {
                            Where = ui.Where
                        });
                    }).ToList();
                }
            }

            if (this.SystemVersioned != null)
            {
                result.Add(new Index(this, this.SystemVersioned.Columns().PreAnd(this.PrimaryKey).ToArray()));
            }

            return(result);
        }
Beispiel #4
0
        public virtual UniqueIndex GenerateUniqueIndex(ITable table, UniqueIndexAttribute attribute)
        {
            if (attribute == null)
            {
                return(null);
            }

            var result = new UniqueIndex(table, Index.GetColumnsFromFields(this))
            {
                AvoidAttachToUniqueIndexes = attribute.AvoidAttachToUniqueIndexes
            };

            if (attribute.AllowMultipleNulls)
            {
                result.Where = IndexWhereExpressionVisitor.IsNull(this, false);
            }

            return(result);
        }
        public List <Index> GeneratAllIndexes()
        {
            IEnumerable <EntityField> fields = Fields.Values.AsEnumerable();

            if (Mixins != null)
            {
                fields = fields.Concat(Mixins.Values.SelectMany(m => m.Fields.Values));
            }

            var result = fields.SelectMany(f => f.Field.GenerateIndexes(this)).ToList();

            if (MultiColumnIndexes != null)
            {
                result.AddRange(MultiColumnIndexes);
            }

            if (result.OfType <UniqueIndex>().Any())
            {
                List <IColumn> attachedFields = fields.Where(f => f.FieldInfo.GetCustomAttribute <AttachToUniqueIndexesAttribute>() != null)
                                                .SelectMany(f => Index.GetColumnsFromFields(f.Field))
                                                .ToList();

                if (attachedFields.Any())
                {
                    result = result.Select(ix =>
                    {
                        var ui = ix as UniqueIndex;
                        if (ui == null || ui.AvoidAttachToUniqueIndexes)
                        {
                            return(ix);
                        }

                        return(new UniqueIndex(ui.Table, ui.Columns.Concat(attachedFields).ToArray())
                        {
                            Where = ui.Where
                        });
                    }).ToList();
                }
            }

            return(result);
        }
Beispiel #6
0
        static IColumn[] GetColumns <T>(IFieldFinder finder, Expression <Func <T, object> > field)
        {
            Type type = RemoveCasting(ref field);

            Field f = Schema.FindField(finder, Reflector.GetMemberList(field));

            if (type != null)
            {
                var ib = f as FieldImplementedBy;
                if (ib == null)
                {
                    throw new InvalidOperationException("Casting only supported for {0}".FormatWith(typeof(FieldImplementedBy).Name));
                }

                return((from ic in ib.ImplementationColumns
                        where type.IsAssignableFrom(ic.Key)
                        select(IColumn) ic.Value).ToArray());
            }

            return(Index.GetColumnsFromFields(f));
        }