C# 如何在C中使用Dapper将对象放入字典?

C# 如何在C中使用Dapper将对象放入字典?,c#,sql-server,dictionary,dapper,C#,Sql Server,Dictionary,Dapper,我有一本字典如下: Dictionary<string,SP> dict; 上述代码不起作用。如何使用上述信息创建SP对象。我有一个构造函数,它接受这三个参数 创建合适的模型 public class SP { public string RoutineName { get; set; } public DateTime Created { get; set; } public DateTime Modified { get; set; } } 将查询映射

我有一本字典如下:

Dictionary<string,SP> dict;
上述代码不起作用。如何使用上述信息创建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);
创建合适的模型

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);

@regal它还必须有一个无参数构造函数。@regal它还必须有一个无参数构造函数。