如果一个项目中实体太多也挺麻烦, 虽然说面向对象编程,但是如果只返回两个字段也需要建一个实体那多麻烦, 基于这个问题dynamic就很好的解决这些事
public static List<dynamic> BugSellTop5Desc(int coinId, int currencyId,int type)
{
var sql = string.Empty;
var list = SqlDapperHelper.ExecuteReaderReturnList<dynamic>(sql, new
{
CurrencyID = currencyId,
CoinID = coinId
});
return list;
}
调用
var list = SellOutService.BugSellTop5Desc(coinId, currencyId, type);
resultMsg.statue = Convert.ToInt32(StatueEnum.Success);
resultMsg.data = list.Select(item=>new
{
Price=item.Price.ToString(),
TotalNum= item.TotalNum.ToString(),
}); //或者不需要select一样可以, 这里只是前端要求用string类型故处理下
当然话会所话来, dynamic一样可以用object代替,
public static List<object> BugSellTop5Desc(int coinId, int currencyId,int type)
{
var sql = string.Empty;
var list = SqlDapperHelper.ExecuteReaderReturnList<object>(sql, new
{
CurrencyID = currencyId,
CoinID = coinId
});
return list;
}
效果一样........时间很紧,干活去了