Пример #1
0
        public virtual string DropTable <T>()
        {
            IObjectMapInfo mapInfo = _cache.GetMapInfo(typeof(T), true);

            try
            {
                StringBuilder str = new StringBuilder();
                str.Append(_tr.DropTable).Append(_tr.GetEscapedTableName(mapInfo.Table.LocalName));
                return(str.ToString());
            }
            catch (Exception ex)
            {
                throw ex.CreateWrapException <SQLGenerateException>();
            }
        }
Пример #2
0
        protected override Expression VisitMember(MemberExpression m)
        {
            if (m.Expression != null && m.Expression.NodeType == ExpressionType.Parameter)
            {
                Visit(m.Expression);

                var map = _cache.GetMapInfo(m.Expression.Type, true);
                _str.Append(_tr.MemberAccess);
                string colName = map.GetColumnFromProperty(m.Member.Name);
                _str.Append(_tr.GetEscapedColumnName(colName));
                return(m);
            }
            ParseExceptionHelper.ThrowNotSupportedExpression(m);
            return(m);
        }
Пример #3
0
        private void Visit(SingleEntityView sv)
        {
            var map = _cache.GetMapInfo(sv.EntityType, true);

            _str.Append(_tr.GetEscapedTableName(map.Table.LocalName));
            if (!string.IsNullOrEmpty(sv.Alias))
            {
                _str.Append(SPACE).Append(_tr.GetEscapedTableName(sv.Alias));
            }
        }
Пример #4
0
        private void Visit(SingleEntityView s)
        {
            var map = _cache.GetMapInfo(s.EntityType, true);

            string prefix = s.Alias ?? map.Table.LocalName;

            foreach (var pMap in map.PropertyMaps)
            {
                _str.Append(_tr.GetEscapedTableName(prefix)).Append(_tr.MemberAccess).Append(_tr.GetEscapedColumnName(pMap.ColumnName))
                .Append(_tr.As).Append(_tr.GetEscapedColumnName(prefix + pMap.ColumnName)).Append(_tr.ColumnDelimiter);
            }
        }
Пример #5
0
        public static string ChooseNameFromView(this ParameterExpression p, IEnumerable <SingleEntityView> svList, IObjectMapInfoCache cache)
        {
            var matchType = from v in svList
                            where v.EntityType == p.Type
                            select v;

            switch (matchType.Count())
            {
            case 0:
                ParseExceptionHelper.ThrowTypeNotDefinedInView(p);
                break;

            case 1:
                SingleEntityView view = matchType.First();
                if ((!string.IsNullOrEmpty(view.Alias)) && view.Alias != p.Name)
                {
                    ParseExceptionHelper.ThrowParameterNameNotMatchViewAlias(p.Name, view.Alias, view.EntityType);
                }

                if (!string.IsNullOrEmpty(view.Alias))
                {
                    return(view.Alias);
                }
                else
                {
                    var map = cache.GetMapInfo(p.Type, true);
                    return(map.Table.LocalName);
                }

            default:
                var q = from v in matchType
                        where v.Alias == p.Name
                        select v;

                switch (q.Count())
                {
                case 0:
                    ParseExceptionHelper.ThrowNoAliasForParameterName(p);
                    break;

                case 1:
                    return(q.First().Alias);

                default:
                    ParseExceptionHelper.ThrowMultiTypeHaveSameAlias(p);
                    break;
                }

                break;
            }
            return(string.Empty);
        }
Пример #6
0
        public virtual string FindByPK <T>(T pk)
        {
            pk.ThrowIfNullArgument(nameof(pk));
            var map = _cache.GetMapInfo(typeof(T), true);

            if (map.PrimaryKeyMaps.Count() == 0)
            {
                GenerateExceptionHelper.ThrowNoPrimaryKeyDefine(typeof(T));
            }
            try
            {
                StringBuilder str = new StringBuilder();

                str.Append(_tr.Select).Append(_cb.BuildSelectColumns(map)).Append(_tr.From).Append(_tr.GetEscapedTableName(map.Table.LocalName));
                str.Append(_tr.Where).Append(_cb.BuildWherePrimaryKey(map, pk));

                return(str.ToString());
            }
            catch (Exception ex)
            {
                throw ex.CreateWrapException <SQLGenerateException>();
            }
        }
Пример #7
0
        public static string ChooseNameFromView(this ParameterExpression p, IEnumerable<SingleEntityView> svList, IObjectMapInfoCache cache)
        {
            var matchType = from v in svList
                            where v.EntityType == p.Type
                            select v;

            switch (matchType.Count())
            {
                case 0:
                    ParseExceptionHelper.ThrowTypeNotDefinedInView(p);
                    break;

                case 1:
                    SingleEntityView view = matchType.First();
                    if ((!string.IsNullOrEmpty(view.Alias)) && view.Alias != p.Name)
                        ParseExceptionHelper.ThrowParameterNameNotMatchViewAlias(p.Name, view.Alias, view.EntityType);

                    if (!string.IsNullOrEmpty(view.Alias))
                        return view.Alias;
                    else
                    {
                        var map = cache.GetMapInfo(p.Type, true);
                        return map.Table.LocalName;
                    }

                default:
                    var q = from v in matchType
                            where v.Alias == p.Name
                            select v;

                    switch (q.Count())
                    {
                        case 0:
                            ParseExceptionHelper.ThrowNoAliasForParameterName(p);
                            break;

                        case 1:
                            return q.First().Alias;

                        default:
                            ParseExceptionHelper.ThrowMultiTypeHaveSameAlias(p);
                            break;
                    }

                    break;
            }
            return string.Empty;
        }
Пример #8
0
        public void TestLoadFromXml()
        {
            var info = _cache.GetMapInfo(typeof(SampleEntity.MSSql.Person), true);

            Assert.IsNotNull(info);
        }