예제 #1
0
 public void Init(ColumnMapper columnMapper, Type baseType)
 {
     var otherColumns = columnMapper.Map(TargetType);
     var reference = otherColumns.FirstOrDefault(c => c.ReferenceTable != null && c.ReferenceTable.BaseType == baseType);
     if (reference != null)
     {
         //1-to-many
     }
     else
     {
         //many-to-many, auto cross reference table needed
         //collection.AddCrossTable();
     }
 }
예제 #2
0
        protected override Expression VisitProjection(ProjectionExpression proj)
        {
            if (isTopLevel)
            {
                isTopLevel         = false;
                this.currentSelect = proj.Select;
                Expression projector = this.Visit(proj.Projector);
                if (projector != proj.Projector || this.currentSelect != proj.Select)
                {
                    return(new ProjectionExpression(this.currentSelect, projector, proj.Aggregator));
                }
                return(proj);
            }

            if (proj.IsSingleton && this.CanJoinOnServer(this.currentSelect))
            {
                TableAlias newAlias = new TableAlias();
                this.currentSelect = this.currentSelect.AddRedundantSelect(this.language, newAlias);

                // remap any references to the outer select to the new alias;
                SelectExpression source = (SelectExpression)ColumnMapper.Map(proj.Select, newAlias, this.currentSelect.Alias);

                // add outer-join test
                ProjectionExpression pex = this.language.AddOuterJoinTest(new ProjectionExpression(source, proj.Projector));

                var pc = ColumnProjector.ProjectColumns(this.language, pex.Projector, this.currentSelect.Columns, this.currentSelect.Alias, newAlias, proj.Select.Alias);

                JoinExpression join = new JoinExpression(JoinType.OuterApply, this.currentSelect.From, pex.Select, null);

                this.currentSelect = new SelectExpression(this.currentSelect.Alias, pc.Columns, join, null);
                return(this.Visit(pc.Projector));
            }

            var saveTop    = this.isTopLevel;
            var saveSelect = this.currentSelect;

            this.isTopLevel    = true;
            this.currentSelect = null;
            Expression result = base.VisitProjection(proj);

            this.isTopLevel    = saveTop;
            this.currentSelect = saveSelect;
            return(result);
        }
예제 #3
0
        public void ColumnMapping()
        {
            var table   = new TableAttribute("Lorem", "ipsum");
            var mapper  = new ColumnMapper(null);
            var columns = mapper.Map <EntityBase>(table);

            Assert.IsTrue(columns.All(c => c.TableName == "Lorem" && c.TableSchema == "ipsum"));

            var discriminator = columns[0];

            Assert.AreEqual(discriminator.ColumnName, ColumnMapper.DiscriminatorColumnName);
            Assert.AreEqual(discriminator.ColumnType, "nvarchar(255)");
            Assert.IsNull(discriminator.DeclaringTypes);
            Assert.IsNull(discriminator.PropertyName);

            /* EntityBase */
            var seqEntityBase = new List <Type> {
                typeof(EntityBase)
            };

            var id = columns[1];

            Assert.AreEqual(id.ColumnName, "Id");
            Assert.AreEqual(id.ColumnType, "int");
            Assert.IsTrue(id.DeclaringTypes.SequenceEqual(seqEntityBase));
            Assert.AreEqual(id.PropertyName, "Id");

            var entityId = columns[2];

            Assert.AreEqual(entityId.ColumnName, "EntityId");
            Assert.AreEqual(entityId.ColumnType, "uniqueidentifier");
            Assert.IsTrue(entityId.DeclaringTypes.SequenceEqual(seqEntityBase));
            Assert.AreEqual(entityId.PropertyName, "EntityId");

            var name = columns[3];

            Assert.AreEqual(name.ColumnName, "Name");
            Assert.AreEqual(name.ColumnType, "nvarchar(max)");
            Assert.IsTrue(name.DeclaringTypes.SequenceEqual(seqEntityBase));
            Assert.AreEqual(name.PropertyName, "Name");

            var date = columns[4];

            Assert.AreEqual(date.ColumnName, "Date");
            Assert.AreEqual(date.ColumnType, "datetime2");
            Assert.IsTrue(date.DeclaringTypes.SequenceEqual(seqEntityBase));
            Assert.AreEqual(date.PropertyName, "Date");

            /* Class A */
            var seqClassA = new List <Type> {
                typeof(ClassA)
            };
            var seqClassAB = new List <Type> {
                typeof(ClassA), typeof(ClassB)
            };

            var number1 = columns[5];

            Assert.AreEqual(number1.ColumnName, "NumberOfSomething");
            Assert.AreEqual(number1.ColumnType, "int");
            Assert.IsTrue(number1.DeclaringTypes.SequenceEqual(seqClassAB));
            Assert.AreEqual(number1.PropertyName, "NumberOfSomething");

            var createdOn = columns[6];

            Assert.AreEqual(createdOn.ColumnName, "CreatedOn");
            Assert.AreEqual(createdOn.ColumnType, "datetime2");
            Assert.IsTrue(createdOn.DeclaringTypes.SequenceEqual(seqClassA));
            Assert.AreEqual(createdOn.PropertyName, "CreatedOn");

            /* Class B */
            var seqClassBC = new List <Type> {
                typeof(ClassB), typeof(ClassC)
            };

            var text = columns[7];

            Assert.AreEqual(text.ColumnName, "Text");
            Assert.AreEqual(text.ColumnType, "nvarchar(max)");
            Assert.IsTrue(text.DeclaringTypes.SequenceEqual(seqClassBC));
            Assert.AreEqual(text.PropertyName, "Text");

            /* Class D */
            var seqClassD = new List <Type> {
                typeof(ClassD)
            };

            var number2 = columns[8];

            Assert.AreEqual(number2.ColumnName, "ClassDNumberOfSomething");
            Assert.AreEqual(number2.ColumnType, "bigint");
            Assert.IsTrue(number2.DeclaringTypes.SequenceEqual(seqClassD));
            Assert.AreEqual(number2.PropertyName, "NumberOfSomething");

            /* Class E */
            var seqClassE = new List <Type> {
                typeof(ClassE)
            };

            var lorem = columns[9];

            Assert.AreEqual(lorem.ColumnName, "Lorem");
            Assert.AreEqual(lorem.ColumnType, "nvarchar(max)");
            Assert.IsTrue(lorem.DeclaringTypes.SequenceEqual(seqClassE));
            Assert.AreEqual(lorem.PropertyName, "Lorem");

            Assert.AreEqual(columns.Count(), 10);
        }
예제 #4
0
        // FIX_PERF
        private static void setFeatureRowFromIFeatureDataRecord(IFeatureDataRecord srcFeature,
                                                                FeatureDataRow targetFeature,
                                                                ColumnMapper columnMapper,
                                                                ICoordinateTransformation transform,
                                                                IGeometryFactory geoFactory)
        {
            //for (Int32 i = 0; i < srcFeature.FieldCount; i++)
            //{
            //    String colName = srcFeature.GetName(i);
            //    targetFeature[colName] = srcFeature.GetValue(i);
            //}
            if (transform != null)//jd: to prevent case when transform is null -  probably because a test was done earlier. need to check
            {
                if (srcFeature.Geometry.SpatialReference.EqualParams(transform.Target))
                {
                    transform = null;
                }
            }

            srcFeature.GetValues(columnMapper.SourceValues);
            targetFeature.ItemArray = columnMapper.Map();
            targetFeature.Geometry = transform == null
                                         ? srcFeature.Geometry
                                         : transform.Transform(srcFeature.Geometry, geoFactory);
            targetFeature.IsFullyLoaded = targetFeature.IsFullyLoaded || srcFeature.IsFullyLoaded;
        }
예제 #5
0
        public void ColumnMapping()
        {
            var table = new TableAttribute("Lorem", "ipsum");
            var mapper = new ColumnMapper(null);
            var columns = mapper.Map<EntityBase>(table);

            Assert.IsTrue(columns.All(c => c.TableName == "Lorem" && c.TableSchema == "ipsum"));

            var discriminator = columns[0];
            Assert.AreEqual(discriminator.ColumnName, ColumnMapper.DiscriminatorColumnName);
            Assert.AreEqual(discriminator.ColumnType, "nvarchar(255)");
            Assert.IsNull(discriminator.DeclaringTypes);
            Assert.IsNull(discriminator.PropertyName);

            /* EntityBase */
            var seqEntityBase = new List<Type> { typeof (EntityBase) };

            var id = columns[1];
            Assert.AreEqual(id.ColumnName, "Id");
            Assert.AreEqual(id.ColumnType, "int");
            Assert.IsTrue(id.DeclaringTypes.SequenceEqual(seqEntityBase));
            Assert.AreEqual(id.PropertyName, "Id");

            var entityId = columns[2];
            Assert.AreEqual(entityId.ColumnName, "EntityId");
            Assert.AreEqual(entityId.ColumnType, "uniqueidentifier");
            Assert.IsTrue(entityId.DeclaringTypes.SequenceEqual(seqEntityBase));
            Assert.AreEqual(entityId.PropertyName, "EntityId");

            var name = columns[3];
            Assert.AreEqual(name.ColumnName, "Name");
            Assert.AreEqual(name.ColumnType, "nvarchar(max)");
            Assert.IsTrue(name.DeclaringTypes.SequenceEqual(seqEntityBase));
            Assert.AreEqual(name.PropertyName, "Name");

            var date = columns[4];
            Assert.AreEqual(date.ColumnName, "Date");
            Assert.AreEqual(date.ColumnType, "datetime2");
            Assert.IsTrue(date.DeclaringTypes.SequenceEqual(seqEntityBase));
            Assert.AreEqual(date.PropertyName, "Date");

            /* Class A */
            var seqClassA = new List<Type> { typeof(ClassA) };
            var seqClassAB = new List<Type> { typeof(ClassA), typeof(ClassB) };

            var number1 = columns[5];
            Assert.AreEqual(number1.ColumnName, "NumberOfSomething");
            Assert.AreEqual(number1.ColumnType, "int");
            Assert.IsTrue(number1.DeclaringTypes.SequenceEqual(seqClassAB));
            Assert.AreEqual(number1.PropertyName, "NumberOfSomething");

            var createdOn = columns[6];
            Assert.AreEqual(createdOn.ColumnName, "CreatedOn");
            Assert.AreEqual(createdOn.ColumnType, "datetime2");
            Assert.IsTrue(createdOn.DeclaringTypes.SequenceEqual(seqClassA));
            Assert.AreEqual(createdOn.PropertyName, "CreatedOn");

            /* Class B */
            var seqClassBC = new List<Type> { typeof(ClassB), typeof(ClassC) };

            var text = columns[7];
            Assert.AreEqual(text.ColumnName, "Text");
            Assert.AreEqual(text.ColumnType, "nvarchar(max)");
            Assert.IsTrue(text.DeclaringTypes.SequenceEqual(seqClassBC));
            Assert.AreEqual(text.PropertyName, "Text");

            /* Class D */
            var seqClassD = new List<Type> { typeof(ClassD) };

            var number2 = columns[8];
            Assert.AreEqual(number2.ColumnName, "ClassDNumberOfSomething");
            Assert.AreEqual(number2.ColumnType, "bigint");
            Assert.IsTrue(number2.DeclaringTypes.SequenceEqual(seqClassD));
            Assert.AreEqual(number2.PropertyName, "NumberOfSomething");

            /* Class E */
            var seqClassE = new List<Type> { typeof(ClassE) };

            var lorem = columns[9];
            Assert.AreEqual(lorem.ColumnName, "Lorem");
            Assert.AreEqual(lorem.ColumnType, "nvarchar(max)");
            Assert.IsTrue(lorem.DeclaringTypes.SequenceEqual(seqClassE));
            Assert.AreEqual(lorem.PropertyName, "Lorem");

            Assert.AreEqual(columns.Count(), 10);
        }
예제 #6
0
        protected override Expression VisitProjection(ProjectionExpression proj)
        {
            SelectExpression save = this.currentSelect;

            this.currentSelect = proj.Select;
            try
            {
                if (!this.isTopLevel)
                {
                    if (this.CanJoinOnClient(this.currentSelect))
                    {
                        // make a query that combines all the constraints from the outer queries into a single select
                        SelectExpression newOuterSelect = (SelectExpression)QueryDuplicator.Duplicate(save);

                        // remap any references to the outer select to the new alias;
                        SelectExpression newInnerSelect = (SelectExpression)ColumnMapper.Map(proj.Select, newOuterSelect.Alias, save.Alias);
                        // add outer-join test
                        ProjectionExpression newInnerProjection = this.language.AddOuterJoinTest(new ProjectionExpression(newInnerSelect, proj.Projector));
                        newInnerSelect = newInnerProjection.Select;
                        Expression newProjector = newInnerProjection.Projector;

                        TableAlias newAlias = new TableAlias();
                        var        pc       = ColumnProjector.ProjectColumns(this.language, newProjector, null, newAlias, newOuterSelect.Alias, newInnerSelect.Alias);

                        JoinExpression   join         = new JoinExpression(JoinType.OuterApply, newOuterSelect, newInnerSelect, null);
                        SelectExpression joinedSelect = new SelectExpression(newAlias, pc.Columns, join, null, null, null, proj.IsSingleton, null, null, false);

                        // apply client-join treatment recursively
                        this.currentSelect = joinedSelect;
                        newProjector       = this.Visit(pc.Projector);

                        // compute keys (this only works if join condition was a single column comparison)
                        List <Expression> outerKeys = new List <Expression>();
                        List <Expression> innerKeys = new List <Expression>();
                        if (this.GetEquiJoinKeyExpressions(newInnerSelect.Where, newOuterSelect.Alias, outerKeys, innerKeys))
                        {
                            // outerKey needs to refer to the outer-scope's alias
                            var outerKey = outerKeys.Select(k => ColumnMapper.Map(k, save.Alias, newOuterSelect.Alias));
                            // innerKey needs to refer to the new alias for the select with the new join
                            var innerKey = innerKeys.Select(k => ColumnMapper.Map(k, joinedSelect.Alias, ((ColumnExpression)k).Alias));
                            ProjectionExpression newProjection = new ProjectionExpression(joinedSelect, newProjector, proj.Aggregator);
                            return(new ClientJoinExpression(newProjection, outerKey, innerKey));
                        }
                    }
                    else
                    {
                        bool saveJoin = this.canJoinOnClient;
                        this.canJoinOnClient = false;
                        var result = base.VisitProjection(proj);
                        this.canJoinOnClient = saveJoin;
                        return(result);
                    }
                }
                else
                {
                    this.isTopLevel = false;
                }
                return(base.VisitProjection(proj));
            }
            finally
            {
                this.currentSelect = save;
            }
        }