Пример #1
0
        protected virtual bool ShouldSelectField(Field field)
        {
            if (DistinctFields != null)
            {
                return(DistinctFields.Contains(field));
            }

            var mode = field.MinSelectLevel;

            if (mode == SelectLevel.Always)
            {
                return(true);
            }

            bool isPrimaryKey = (field.Flags & FieldFlags.PrimaryKey) == FieldFlags.PrimaryKey;

            if (isPrimaryKey && mode != SelectLevel.Explicit)
            {
                return(true);
            }

            if (mode == SelectLevel.Auto)
            {
                bool notMapped = (field.Flags & FieldFlags.NotMapped) == FieldFlags.NotMapped;
                if (notMapped)
                {
                    // normally not-mapped fields are skipped in SelectFields method,
                    // but some relations like MasterDetailRelation etc. use this method (ShouldSelectFields)
                    // to determine if they should populate those fields themselves.
                    // so we return here Explicit so that they only populate them if such
                    // fields are explicitly included (e.g. related column is visible)
                    mode = SelectLevel.Explicit;
                }
                else
                {
                    // assume that non-foreign calculated and reflective fields should be selected in list mode
                    bool isForeign = (field.Flags & FieldFlags.Foreign) == FieldFlags.Foreign;
                    mode = isForeign ? SelectLevel.Details : SelectLevel.List;
                }
            }

            bool explicitlyExcluded = Request.ExcludeColumns != null &&
                                      (Request.ExcludeColumns.Contains(field.Name) ||
                                       (field.PropertyName != null && Request.ExcludeColumns.Contains(field.PropertyName)));

            bool explicitlyIncluded = !explicitlyExcluded && Request.IncludeColumns != null &&
                                      (Request.IncludeColumns.Contains(field.Name) ||
                                       (field.PropertyName != null && Request.IncludeColumns.Contains(field.PropertyName)));

            if (isPrimaryKey)
            {
                return(explicitlyIncluded);
            }

            if (explicitlyExcluded)
            {
                return(false);
            }

            if (explicitlyIncluded)
            {
                return(true);
            }

            var selection = Request.ColumnSelection;

            return(selection switch
            {
                ColumnSelection.List => mode <= SelectLevel.List,
                ColumnSelection.Details => mode <= SelectLevel.Details,
                _ => false,
            });
Пример #2
0
        protected virtual bool ShouldSelectField(Field field)
        {
            if (DistinctFields != null)
            {
                return(DistinctFields.Contains(field));
            }

            var mode = field.MinSelectLevel;

            if (mode == SelectLevel.Always)
            {
                return(true);
            }

            bool isPrimaryKey = (field.Flags & FieldFlags.PrimaryKey) == FieldFlags.PrimaryKey;

            if (isPrimaryKey && mode != SelectLevel.Explicit)
            {
                return(true);
            }

            if (mode == SelectLevel.Auto)
            {
                // assume that non-foreign calculated and reflective fields should be selected in list mode
                bool isForeign = (field.Flags & FieldFlags.Foreign) == FieldFlags.Foreign;
                mode = isForeign ? SelectLevel.Details : SelectLevel.List;
            }

            bool explicitlyExcluded = Request.ExcludeColumns != null &&
                                      (Request.ExcludeColumns.Contains(field.Name) ||
                                       (field.PropertyName != null && Request.ExcludeColumns.Contains(field.PropertyName)));

            bool explicitlyIncluded = !explicitlyExcluded && Request.IncludeColumns != null &&
                                      (Request.IncludeColumns.Contains(field.Name) ||
                                       (field.PropertyName != null && Request.IncludeColumns.Contains(field.PropertyName)));

            if (isPrimaryKey)
            {
                return(explicitlyIncluded);
            }

            if (explicitlyExcluded)
            {
                return(false);
            }

            if (explicitlyIncluded)
            {
                return(true);
            }

            var selection = Request.ColumnSelection;

            switch (selection)
            {
            case ColumnSelection.List:
                return(mode <= SelectLevel.List);

            case ColumnSelection.Details:
                return(mode <= SelectLevel.Details);

            default:
                return(false);
            }
        }