示例#1
0
        public TEntity GetById <TEntity>(object id) where TEntity : class, new()
        {
            var sql = dapperSqlGenerator?.GetById <TEntity>(id);

            if (!sql.IsNullOrEmpty())
            {
                return(dbConnection.Query <TEntity>(sql, new { Id = id }).SingleOrDefault());
            }
            else
            {
                return(dbConnection.Get <TEntity>(id));
            }
        }
示例#2
0
        public TEntity FindById(object id)
        {
            if (id == null)
            {
                throw new ArgumentNullException("Id needs to have value");
            }

            var sql = dapperSqlGenerator?.GetById <TEntity>(id);

            return(!sql.IsNullOrEmpty()
                ? dbConnection.QuerySingleOrDefault <TEntity>(sql, new { Id = id })
                : dbConnection.Get <TEntity>(id));
        }
示例#3
0
        public async Task <TEntity> FindById(object id, CancellationToken cancellationToken = default)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id), "Id needs to have value");
            }

            var sql = dapperSqlGenerator?.GetById <TEntity>(id);

            if (!sql.IsNullOrEmpty())
            {
                return(await dbConnection.QuerySingleOrDefaultAsync <TEntity>(sql, new { Id = id }));
            }

            return(await dbConnection.GetAsync <TEntity>(id));
        }