예제 #1
0
        public override MappingEntity GetEntity(Type elementType, string tableId)
        {
            if (tableId == null)
            {
                tableId = GetTableId(elementType);
            }

            MappingEntity entity;

            rwLock.AcquireReaderLock(Timeout.Infinite);
            if (!entities.TryGetValue(tableId, out entity))
            {
                rwLock.ReleaseReaderLock();
                rwLock.AcquireWriterLock(Timeout.Infinite);
                if (!entities.TryGetValue(tableId, out entity))
                {
                    entity = new CompositiveMappingEntity(elementType, tableId);
                    this.entities.Add(tableId, entity);
                }
                rwLock.ReleaseWriterLock();
            }
            else
            {
                rwLock.ReleaseReaderLock();
            }

            return(entity);
        }
예제 #2
0
        public override string GetTableName(MappingEntity entity)
        {
            CompositiveMappingEntity en = (CompositiveMappingEntity)entity;

            if (en.Table != null)
            {
                return(en.Table.Name);
            }

            return(base.GetTableName(entity));
        }
예제 #3
0
        public override bool IsGenerated(MappingEntity entity, MemberInfo member)
        {
            CompositiveMappingEntity en = (CompositiveMappingEntity)entity;
            CompositiveMappingMember mm = en.GetMappingMember(member.Name);

            if (mm != null && mm.Column != null)
            {
                return(mm.Column.IsGenerated);
            }

            return(base.IsGenerated(entity, member));
        }
예제 #4
0
        public override bool IsColumn(MappingEntity entity, MemberInfo member)
        {
            CompositiveMappingEntity en = (CompositiveMappingEntity)entity;
            CompositiveMappingMember mm = en.GetMappingMember(member.Name);

            if (mm != null)
            {
                return(!mm.NotMapped);
            }

            return(base.IsColumn(entity, member));
        }
예제 #5
0
        public override string GetColumnName(MappingEntity entity, MemberInfo member)
        {
            CompositiveMappingEntity en = (CompositiveMappingEntity)entity;
            CompositiveMappingMember mm = en.GetMappingMember(member.Name);

            if (mm != null && mm.Column != null)
            {
                return(mm.Column.Name);
            }

            return(base.GetColumnName(entity, member));
        }
예제 #6
0
            public override ProjectionExpression GetQueryExpression(MappingEntity entity)
            {
                CompositiveMappingEntity mme = (CompositiveMappingEntity)entity;

                if (mme.Table == null || string.IsNullOrEmpty(mme.Table.View))
                {
                    var tableAlias  = new TableAlias();
                    var selectAlias = new TableAlias();
                    var columns     = new List <ColumnDeclaration>();
                    var aliases     = new Dictionary <string, TableAlias>();

                    var table = new TableExpression(tableAlias, entity, (this.Mapping as BasicMapping).GetTableName(entity));

                    this.GetColumns(entity, aliases, columns);
                    SelectExpression root = new SelectExpression(new TableAlias(), columns, table, null);

                    Expression projector = this.GetEntityExpression(table, entity);
                    var        pc        = ColumnProjector.ProjectColumns(this.Translator.Linguist.Language, projector, null, selectAlias, tableAlias);

                    var proj = new ProjectionExpression(
                        new SelectExpression(selectAlias, pc.Columns, table, null),
                        pc.Projector
                        );

                    return((ProjectionExpression)this.Translator.Police.ApplyPolicy(proj, entity.ElementType));
                }
                else
                {
                    var tableAlias  = new TableAlias();
                    var selectAlias = new TableAlias();
                    var columns     = new List <ColumnDeclaration>();
                    var aliases     = new Dictionary <string, TableAlias>();

                    var table            = new TableExpression(tableAlias, entity, mme.Table.View);
                    ColumnDeclaration cd = new ColumnDeclaration("*", "", new AllColumnExpression(tableAlias), new DbQueryType(SqlDbType.Variant, false, 0, 0, 0));
                    columns.Add(cd);

                    SelectExpression root      = new SelectExpression(new TableAlias(), columns, table, null);
                    Expression       projector = this.GetEntityExpression(table, entity);
                    //var pc = ColumnProjector.ProjectColumns(this.Translator.Linguist.Language, projector, null, selectAlias, tableAlias);

                    var proj = new ProjectionExpression(
                        new SelectExpression(selectAlias, columns, table, null),
                        projector
                        );

                    return((ProjectionExpression)this.Translator.Police.ApplyPolicy(proj, entity.ElementType));
                }
            }