Example #1
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>();
            }
        }
Example #2
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>();
            }
        }