public static IDbSelect Map(
            IDbSelect dbSelect, Type returnType,
            IModelInfoProvider infoProvider, IDbObjectFactory dbFactory, UniqueNameGenerator nameGenerator)
        {
            // If the select returns specified columns, it means there is a constructor in Select,
            // e.g (.Select(d => new { A = d.ABC }))
            // In this case we do not need to add alias to the end result as where will be one in the select
            if (dbSelect.Selection.Any(s => !(s is IDbRefColumn)))
            {
                return(dbSelect);
            }

            var entityInfo = infoProvider.FindEntityInfo(returnType);

            if (!entityInfo.RequirePropertyNameMapping())
            {
                return(dbSelect);
            }

            var alias        = nameGenerator.GenerateAlias(dbSelect, TranslationConstants.SubSelectPrefix, true);
            var newSelectRef = dbFactory.BuildRef(dbSelect, alias);
            var newSelect    = dbFactory.BuildSelect(newSelectRef);

            foreach (var fieldInfo in entityInfo.Columns)
            {
                var column = dbFactory.BuildColumn(
                    newSelectRef, fieldInfo.DbName, fieldInfo.ValType, fieldInfo.PropertyName);

                newSelect.Selection.Add(column);
            }

            return(newSelect);
        }
Ejemplo n.º 2
0
        private static IDbJoin MakeJoin(IDbSelect ownerSelect, IDbObject tempSelect, IDbObjectFactory dbFactory, UniqueNameGenerator nameGenerator)
        {
            var joinAlias = nameGenerator.GenerateAlias(ownerSelect, TranslationConstants.SubSelectPrefix);
            var joinTo    = dbFactory.BuildRef(tempSelect, joinAlias);

            return(dbFactory.BuildJoin(joinTo, ownerSelect));
        }
Ejemplo n.º 3
0
        protected override Expression VisitConstant(ConstantExpression c)
        {
            var entityInfo = _infoProvider.FindEntityInfo(c.Type);

            if (entityInfo != null)
            {
                var dbTable = _dbFactory.BuildTable(entityInfo);
                var dbRef   = _dbFactory.BuildRef(dbTable);

                var dbSelect = _dbFactory.BuildSelect(dbRef);
                dbRef.Alias = _nameGenerator.GenerateAlias(dbSelect, dbTable.TableName);

                _state.ResultStack.Push(dbSelect);
            }
            else if (!c.Type.IsAnonymouse())
            {
                var dbConstant = _dbFactory.BuildConstant(c.Value, true);
                _state.ResultStack.Push(dbConstant);
            }

            return(c);
        }