为什么我用dapper进行的所有搜索都为此workoutdate字段带来一个空(默认的Datetime值)?
StringBuilder query = new StringBuilder();
query.Append("SELECT W.WorkoutId, W.Active, W.GymId, W.Spots, W.UserId, W.WorkoutDate, W.WorkoutStatusId FROM [Workout] W");
public class Workout
{
public Guid WorkoutId { get; private set; }
public Guid UserId { get; set; }
public Guid? GymId { get; set; }
public int WorkoutStatusId { get; set; }
public int Spots { get; set; }
public bool Active { get; set; }
public DateTime WorkoutDate { get; set; }
}
答案 0 :(得分:1)
您的专栏是datetime2。您可以更改Dapper映射列的方式,如下所示:
SqlMapper.AddTypeMap(typeof(DateTime), System.Data.DbType.DateTime2);
另一种方法是将它放在选择中,如下所示:
SELECT CAST(W.WorkoutDate AS datetime) ...
或者,如果您不需要添加datetime2的精度,则可以将列更改为datetime。