我有一个像下面这样的字典:
Dictionary<string,SP> dict;
包含一个字符串和一个 SP 对象。
我想做以下事情
dict = conn.Query("SELECT routine_name,created,modified FROM PROCEDURES").toDictionary (
row => (string)row.Routine_Name,
row => new SP (Name=row.Routine_Name,Created=row.created,Modified=row.modified));
以上代码无效。如何使用上述信息创建 SP 对象。我有一个采用这三个参数的构造函数。
请您参考如下方法:
创建合适的模型
public class SP { public string RoutineName { get; set; } public DateTime Created { get; set; } public DateTime Modified { get; set; } }将您的查询映射到模型属性,将其选择到字典
Dictionary<string, SP> dictionary = connection.Query<SP>(@" SELECT routine_name AS RoutineName, created AS Created, modified AS Modified FROM PROCEDURES ").ToDictionary(m => m.RoutineName, m => m);
