예제 #1
0
        public Implementations FindImplementations(PropertyRoute route)
        {
            if (route.PropertyRouteType == PropertyRouteType.LiteEntity)
            {
                route = route.Parent;
            }

            Type type = route.RootType;

            if (!Tables.ContainsKey(type))
            {
                return(Schema.Current.Settings.GetImplementations(route));
            }

            Field field = TryFindField(Table(type), route.Members);
            //if (field == null)
            //    return Implementations.ByAll;

            FieldReference refField = field as FieldReference;

            if (refField != null)
            {
                return(Implementations.By(refField.FieldType.CleanType()));
            }

            FieldImplementedBy ibField = field as FieldImplementedBy;

            if (ibField != null)
            {
                return(Implementations.By(ibField.ImplementationColumns.Keys.ToArray()));
            }

            FieldImplementedByAll ibaField = field as FieldImplementedByAll;

            if (ibaField != null)
            {
                return(Implementations.ByAll);
            }

            Implementations?implementations = CalculateExpressionImplementations(route);

            if (implementations != null)
            {
                return(implementations.Value);
            }

            var ss = Schema.Current.Settings;

            if (route.Follow(r => r.Parent)
                .TakeWhile(t => t.PropertyRouteType != PropertyRouteType.Root)
                .Any(r => ss.FieldAttribute <IgnoreAttribute>(r) != null))
            {
                var ib  = ss.FieldAttribute <ImplementedByAttribute>(route);
                var iba = ss.FieldAttribute <ImplementedByAllAttribute>(route);

                return(Implementations.TryFromAttributes(route.Type.CleanType(), route, ib, iba) ?? Implementations.By());
            }

            throw new InvalidOperationException("Impossible to determine implementations for {0}".FormatWith(route, typeof(IEntity).Name));
        }
예제 #2
0
        protected override Expression VisitTypeBinary(TypeBinaryExpression b)
        {
            var f = GetField(b.Expression);

            FieldReference fr = f as FieldReference;

            if (fr != null)
            {
                if (b.TypeOperand.IsAssignableFrom(fr.FieldType))
                {
                    sb.Append(fr.Name.SqlEscape() + " IS NOT NULL");
                }
                else
                {
                    throw new InvalidOperationException("A {0} will never be {1}".FormatWith(fr.FieldType.TypeName(), b.TypeOperand.TypeName()));
                }

                return(b);
            }

            FieldImplementedBy fib = f as FieldImplementedBy;

            if (fib != null)
            {
                var imp = fib.ImplementationColumns.Where(kvp => b.TypeOperand.IsAssignableFrom(kvp.Key));

                if (imp.Any())
                {
                    sb.Append(imp.ToString(kvp => kvp.Value.Name.SqlEscape() + " IS NOT NULL", " OR "));
                }
                else
                {
                    throw new InvalidOperationException("No implementation ({0}) will never be {1}".FormatWith(fib.ImplementationColumns.Keys.ToString(t => t.TypeName(), ", "), b.TypeOperand.TypeName()));
                }

                return(b);
            }

            throw new NotSupportedException("'is' only works with ImplementedBy or Reference fields");
        }