Ejemplo n.º 1
0
            protected internal override Expression VisitLiteReference(LiteReferenceExpression lite)
            {
                var reference = Visit(lite.Reference);

                var toStr = Visit(lite.CustomToStr);

                return(Lite.ToLiteFatInternalExpression(reference, toStr ?? Expression.Constant(null, typeof(string))));
            }
Ejemplo n.º 2
0
        protected override Expression VisitLiteReference(LiteReferenceExpression lite)
        {
            var id = binder.GetId(lite.Reference);
            var typeId = binder.GetEntityType(lite.Reference);
            var toStr = LiteToString(lite, typeId);

            return new LiteValueExpression(lite.Type, typeId, id, toStr);
        }
Ejemplo n.º 3
0
        protected internal override Expression VisitLiteReference(LiteReferenceExpression lite)
        {
            var oldInLite = inLite;

            inLite = true;
            var result = base.VisitLiteReference(lite);

            inLite = oldInLite;
            return(result);
        }
Ejemplo n.º 4
0
        internal static Expression EntityIn(LiteReferenceExpression liteReference, IEnumerable <Lite <IEntity> > collection)
        {
            if (collection.IsEmpty())
            {
                return(False);
            }

            Dictionary <Type, PrimaryKey[]> entityIDs = collection.Where(a => a.IdOrNull.HasValue).AgGroupToDictionary(a => a.EntityType, gr => gr.Select(a => a.Id).ToArray());

            return(EntityIn(liteReference.Reference, entityIDs));
        }
Ejemplo n.º 5
0
        protected internal virtual Expression VisitLiteReference(LiteReferenceExpression lite)
        {
            var newRef   = Visit(lite.Reference);
            var newToStr = Visit(lite.CustomToStr);

            if (newRef != lite.Reference || newToStr != lite.CustomToStr)
            {
                return(new LiteReferenceExpression(lite.Type, newRef, newToStr, lite.LazyToStr, lite.EagerEntity));
            }
            return(lite);
        }
Ejemplo n.º 6
0
        protected internal override Expression VisitLiteReference(LiteReferenceExpression lite)
        {
            var id = lite.Reference is ImplementedByAllExpression ||
                     lite.Reference is ImplementedByExpression && ((ImplementedByExpression)lite.Reference).Implementations.Select(imp => imp.Value.ExternalId.ValueType.Nullify()).Distinct().Count() > 1 ?
                     (Expression)binder.GetIdString(lite.Reference) :
                     (Expression)binder.GetId(lite.Reference);

            var typeId = binder.GetEntityType(lite.Reference);
            var toStr  = LiteToString(lite, typeId);

            return(new LiteValueExpression(lite.Type, typeId, id, toStr));
        }
Ejemplo n.º 7
0
        protected internal override Expression VisitLiteReference(LiteReferenceExpression lite)
        {
            var id = lite.Reference is ImplementedByAllExpression || 
                lite.Reference is ImplementedByExpression && ((ImplementedByExpression)lite.Reference).Implementations.Select(imp=>imp.Value.ExternalId.ValueType.Nullify()).Distinct().Count() > 1 ?
                (Expression)binder.GetIdString(lite.Reference) :
                (Expression)binder.GetId(lite.Reference);

            var typeId = binder.GetEntityType(lite.Reference);
            var toStr = LiteToString(lite, typeId);

            return new LiteValueExpression(lite.Type, typeId, id, toStr);
        }
Ejemplo n.º 8
0
        private Expression?LiteToString(LiteReferenceExpression lite, Expression typeId)
        {
            if (lite.CustomToStr != null)
            {
                return(Visit(lite.CustomToStr));
            }

            if (lite.Reference is ImplementedByAllExpression)
            {
                return(null);
            }

            if (lite.LazyToStr)
            {
                return(null);
            }

            if (IsCacheable(typeId))
            {
                return(null);
            }

            if (lite.Reference is EntityExpression entityExp)
            {
                if (entityExp.AvoidExpandOnRetrieving)
                {
                    return(null);
                }

                return(binder.BindMethodCall(Expression.Call(entityExp, EntityExpression.ToStringMethod)));
            }

            if (lite.Reference is ImplementedByExpression ibe)
            {
                if (ibe.Implementations.Any(imp => imp.Value.AvoidExpandOnRetrieving))
                {
                    return(null);
                }

                return(ibe.Implementations.Values.Select(ee =>
                                                         new When(SmartEqualizer.NotEqualNullable(ee.ExternalId, QueryBinder.NullId(ee.ExternalId.ValueType)),
                                                                  binder.BindMethodCall(Expression.Call(ee, EntityExpression.ToStringMethod)))
                                                         ).ToCondition(typeof(string)));
            }

            return(binder.BindMethodCall(Expression.Call(lite.Reference, EntityExpression.ToStringMethod)));
        }
Ejemplo n.º 9
0
        protected internal override Expression VisitLiteReference(LiteReferenceExpression lite)
        {
            if (lite.EagerEntity)
            {
                return(base.VisitLiteReference(lite));
            }

            var id = lite.Reference is ImplementedByAllExpression ||
                     lite.Reference is ImplementedByExpression && ((ImplementedByExpression)lite.Reference).Implementations.Select(imp => imp.Value.ExternalId.ValueType.Nullify()).Distinct().Count() > 1 ?
                     (Expression)binder.GetIdString(lite.Reference) :
                     (Expression)binder.GetId(lite.Reference);

            var typeId = binder.GetEntityType(lite.Reference);
            var toStr  = LiteToString(lite, typeId);

            //var toStr2 = Visit(toStr); //AdditionalBinding in embedded requires it, but makes problems in many other lites in Nominator

            return(new LiteValueExpression(lite.Type, typeId, id, toStr));
        }
Ejemplo n.º 10
0
        private Expression LiteToString(LiteReferenceExpression lite, Expression typeId)
        {
            if (lite.CustomToStr != null)
                return Visit(lite.CustomToStr);

            if (lite.Reference is ImplementedByAllExpression)
                return null;

              if (IsCacheable(typeId))
                return null;

            if (lite.Reference is EntityExpression)
            {
                var ee = (EntityExpression)lite.Reference;
                
                if(ee.AvoidExpandOnRetrieving)
                    return null;

                return binder.BindMethodCall(Expression.Call(lite.Reference, EntityExpression.ToStringMethod));
            }
                
            if(lite.Reference is ImplementedByExpression)
            {
                var ibe = (ImplementedByExpression)lite.Reference;

                if(ibe.Implementations.Any(imp => imp.Value.AvoidExpandOnRetrieving))
                    return null;

                return ibe.Implementations.Values.Select(ee =>
                    new When(SmartEqualizer.NotEqualNullable(ee.ExternalId, QueryBinder.NullId),
                     binder.BindMethodCall(Expression.Call(ee, EntityExpression.ToStringMethod)))
                     ).ToCondition(typeof(string));
            }

            return binder.BindMethodCall(Expression.Call(lite.Reference, EntityExpression.ToStringMethod));
        }
Ejemplo n.º 11
0
 protected internal override Expression VisitLiteReference(LiteReferenceExpression lite)
 {
     return(base.VisitLiteReference(lite));
 }
Ejemplo n.º 12
0
 protected virtual bool CompareLiteReference(LiteReferenceExpression a, LiteReferenceExpression b)
 {
     return(Compare(a.Reference, b.Reference) && Compare(a.CustomToStr, b.CustomToStr));
 }
Ejemplo n.º 13
0
        internal static Expression EntityIn(LiteReferenceExpression liteReference, IEnumerable<Lite<IEntity>> collection)
        {
            if (collection.IsEmpty())
                return False;

            Dictionary<Type, PrimaryKey[]> entityIDs = collection.Where(a => a.IdOrNull.HasValue).AgGroupToDictionary(a => a.EntityType, gr => gr.Select(a => a.Id).ToArray());

            return EntityIn(liteReference.Reference, entityIDs); 
        }
Ejemplo n.º 14
0
 protected virtual Expression VisitLiteReference(LiteReferenceExpression lite)
 {
     var newRef = Visit(lite.Reference);
     var newToStr = Visit(lite.CustomToStr);
     if (newRef != lite.Reference || newToStr != lite.CustomToStr)
         return new LiteReferenceExpression(lite.Type,  newRef, newToStr);
     return lite;
 }
Ejemplo n.º 15
0
        internal static Expression EntityIn(LiteReferenceExpression liteReference, IEnumerable<Lite<IIdentifiable>> collection)
        {
            if (collection.IsEmpty())
                return False;

            Dictionary<Type, object[]> entityIDs = collection.AgGroupToDictionary(a => a.EntityType, gr => gr.Select(a => (object)(a.IdOrNull ?? int.MaxValue)).ToArray());

            return EntityIn(liteReference.Reference, entityIDs); 
        }
Ejemplo n.º 16
0
 protected override Expression VisitLiteReference(LiteReferenceExpression lite)
 {
     return base.VisitLiteReference(lite);
 }