Dapper 能够将此查询映射到car
对象。它知道汽车中的哪个属性去查询中的哪个变量。
Car car = new Car();
conn.Execute(
"UPDATE CAR" +
" SET COLOR=@Color,MODEL=@Model" +
" WHERE ID=@Id", car;
但是我可以在查询中添加另一个变量吗?例如:
int c = 1000;
conn.Execute(
"UPDATE CAR" +
" SET COLOR=@Color,MODEL=@Model,COST=@cost" +
" WHERE ID=@Id", car, new { cost = c };
我想这样做,而不必将汽车对象中的每个属性都与查询中的变量相匹配。这是示例类,但我的真实类中有更多属性。
public class Car {
public int Id { get; set; }
public string Color { get; set; }
public string Model { get; set; }
}