Exemplo n.º 1
0
        public virtual IPropertyMapInfo GetPrimaryKeyNeedBinding <T>()
        {
            var map = _cache.GetMapInfo(typeof(T), true);

            if (map.PrimaryKeyGenerate == PrimaryKeyGenerate.Auto)
            {
                if (map.PKStatus == PrimaryKeyStatus.Single)
                {
                    return(map.PrimaryKeyMaps.First());
                }
                else
                {
                    GenerateExceptionHelper.ThrowPrimaryKeyDefineNotSupport(typeof(T));
                }
            }

            return(null);
        }
Exemplo n.º 2
0
        public virtual string Remove <T>(T entity)
        {
            var map = _cache.GetMapInfo(typeof(T), true);

            if (map.PrimaryKeyMaps.Count() == 0)
            {
                GenerateExceptionHelper.ThrowNoPrimaryKeyDefine(typeof(T));
            }
            try
            {
                StringBuilder str = new StringBuilder();
                str.Append(_tr.Delete).Append(_tr.GetEscapedTableName(map.Table.LocalName));
                str.Append(_tr.Where).Append(_cb.BuildWherePrimaryKey(map, entity));
                return(str.ToString());
            }
            catch (Exception ex)
            {
                throw ex.CreateWrapException <SQLGenerateException>();
            }
        }
Exemplo n.º 3
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>();
            }
        }