コード例 #1
0
        internal static StrongEntityAccessor GetEntityAccessor(this IQueryVisitor visitor, Remotion.Linq.Clauses.FromClauseBase sourceExpression)
        {
            StrongEntityAccessor entityAccessor = null;

            if (typeof(IEntity).GetTypeInfo().IsAssignableFrom(sourceExpression.ItemType))
            {
                sourceExpression = visitor.TransformFromExpression(sourceExpression);
                entityAccessor   = visitor.Query.FindAllComponents <StrongEntityAccessor>().FirstOrDefault(item => item.SourceExpression.EqualsTo(sourceExpression));
                if (entityAccessor == null)
                {
                    Identifier identifier = visitor.Query.FindAllComponents <EntityConstrain>()
                                            .Where(item => (item.TargetExpression.EqualsTo(sourceExpression.FromExpression)) && (item.Value is Identifier))
                                            .Select(item => (Identifier)item.Value)
                                            .FirstOrDefault() ?? new Identifier(visitor.Query.CreateVariableName(sourceExpression.ItemName), sourceExpression.ItemType.FindEntityType());
                    entityAccessor = new StrongEntityAccessor(identifier, sourceExpression);
                    entityAccessor.UnboundGraphName = entityAccessor.About;
                    EntityTypeConstrain constrain = visitor.CreateTypeConstrain(sourceExpression);
                    if ((constrain != null) && (!entityAccessor.Elements.Contains(constrain)))
                    {
                        entityAccessor.Elements.Add(constrain);
                    }
                }
            }

            return(entityAccessor);
        }
コード例 #2
0
        internal static EntityTypeConstrain CreateTypeConstrain(this IQueryVisitor visitor, Remotion.Linq.Clauses.FromClauseBase sourceExpression)
        {
            EntityTypeConstrain result = null;
            Type entityType            = sourceExpression.ItemType.FindEntityType();

            if ((entityType != null) && (entityType != typeof(IEntity)))
            {
                result = visitor.CreateTypeConstrain(entityType, sourceExpression.FromExpression);
            }

            return(result);
        }