62,072
社区成员
发帖
与我相关
我的任务
分享
var lst = tran.CreateCommand("select v.*,b.Type from VoucherItems v left join AccountingBook b on v.BookName=b.Name" +
" left join Voucher a on v.VoucherId=a.Id" +
$" where VoucherId=@id")
.SetParam("id", searchId)
.ExecuteList(x => new VoucherItem
{
Index = x.GetValue<int>("Index"),
BookName = x.GetValue<string>("BookName"),
Customer = x.GetValue<string>("Customer"),
Supplier = x.GetValue<string>("Supplier"),
Department = x.GetValue<string>("Department"),
Personal = x.GetValue<string>("Personal"),
Project = x.GetValue<string>("Project"),
Money = x.GetValue<decimal>("Money"),
Quantity = x.GetValue<double>("Quantity")
});
1、tran.CreateCommand 这个是事务带的方法么?我一直都是用SqlDataAdapter把数据填充到datatable中去
2、 $" where VoucherId=@id") 这个$是什么意思,如果代表string.format好像不是这么用的
3、ExecuteList这个方法从网上没找到相关介绍啊,还有SetParamvar lst = tran.CreateCommand("select v.*,b.Type from VoucherItems v left join AccountingBook b on v.BookName=b.Name" +
" left join Voucher a on v.VoucherId=a.Id" +
$" where VoucherId=@id")
.SetParam("id", searchId)
.ExecuteList(x => new VoucherItem
{
Index = x.GetValue<int>("Index"),
BookName = x.GetValue<string>("BookName"),
Customer = x.GetValue<string>("Customer"),
Supplier = x.GetValue<string>("Supplier"),
Department = x.GetValue<string>("Department"),
Personal = x.GetValue<string>("Personal"),
Project = x.GetValue<string>("Project"),
Money = x.GetValue<decimal>("Money"),
Quantity = x.GetValue<double>("Quantity")
});
这就返回了一组业务实体对象,不需要低效率地去搞什么“框架”,自己写上十几行 SQLHelper 代码去对.net 的 DBData 框架进行封装,得到更好的查询和参数语句就行了。编程不一定对于中间层的底层纠结一或者两种编程方法,而是要把精力放到更前端和更后端的大问题上。