Example #1
0
 protected override Task <IEnumerable <Blogger> > QueryAsync(string sql, object parameters = null, IDbConnection connection = null)
 {
     if (connection == null)
     {
         using (connection = DBSessionFactory.CreateDbConnection(ConnectionString))
         {
             return(connection.QueryAsync <Blogger, Category, Blogger>(sql, (b, c) => { b.Category = c; return b; }, parameters, splitOn: "Name"));
         }
     }
     else
     {
         return(connection.QueryAsync <Blogger, Category, Blogger>(sql, (b, c) => { b.Category = c; return b; }, parameters, splitOn: "Name"));
     }
 }
Example #2
0
        public async Task <Blogger> GetDetailAsync(int id)
        {
            string sql = @$ "SELECT TOP 1 b.*, c.Name FROM {TableName} AS b
                        LEFT JOIN Category AS c ON b.CategoryId=c.Id
                        WHERE b.IsDelete=0 AND b.IsShow=1 AND b.Id=@Id";

            using (IDbConnection connection = DBSessionFactory.CreateDbConnection(ConnectionString))
            {
                var result = await connection.QueryAsync <Blogger, Category, Blogger>(sql, (b, c) => { b.Category = c; return(b); }, new
                {
                    Id = id
                }, splitOn : "Name");

                return(result.FirstOrDefault());
            }
        }