I have a class named "order"
public class order{
public string INTERNET_PRICE{get;set;}
public string SUGGEST_PRICE{get;set;}
}
Then I want using Dapper to select a new column named "Total"
Total column's value is INTERNET_PRICE + SUGGEST_PRICE
If I cannot add new member to order class or create new class.
Is there have some way can do this?
using(var connection=this.Connection){
var sql=@"select INTERNET_PRICE,SUGGEST_PRICE,
INTERNET_PRICE+SUGGEST_PRICE as Total
from BS_GOODS_CHANGEPRICE";
var result=connection.Query<order>(sql);
result.Dump();
}
I agree with all the comments...
Below example is just to demo one of the many options using a dynamic object:
var result = _sqlConnection.Query<dynamic>("select a, b, total = a+ b from (select a = 10, b = 20) data").Single();
var total = result.total;
Assert.That(total, Is.EqualTo(30));
You can also look up mapping results to a Tuple.