C# 映射字典属性petapoco
我有一个模型,它的属性之一是字典C# 映射字典属性petapoco,c#,poco,petapoco,C#,Poco,Petapoco,我有一个模型,它的属性之一是字典 public class PupilCache { public int Id { get; set; } public DateTime CreateDate { get; set; } public string Name { get; set; } public string Username { get; set; } public string Email { get; set; } public Dic
public class PupilCache {
public int Id { get; set; }
public DateTime CreateDate { get; set; }
public string Name { get; set; }
public string Username { get; set; }
public string Email { get; set; }
public Dictionary<string, object> Properties { get; set; }
}
公共类PupilCache{
公共int Id{get;set;}
公共日期时间CreateDate{get;set;}
公共字符串名称{get;set;}
公共字符串用户名{get;set;}
公共字符串电子邮件{get;set;}
公共字典属性{get;set;}
}
此字典的键是SQL中连接表的所有列。peta poco是否可以在一次查询中检索此信息?此处为PetaPoco维护程序。是的,这应该可以使用fetch方法实现,您为该方法提供了一个回调来填充Poco关系。但是,您需要提供Poco,以便PetaPoco可以将DB中的键值列映射到Poco(必需) 看到这个了吗
/// <summary>
/// Perform a multi-poco fetch
/// </summary>
/// <typeparam name="T1">The first POCO type</typeparam>
/// <typeparam name="T2">The second POCO type</typeparam>
/// <typeparam name="TRet">The returned list POCO type</typeparam>
/// <param name="cb">A callback function to connect the POCO instances, or null to automatically guess the relationships</param>
/// <param name="sql">The SQL query to be executed</param>
/// <param name="args">Arguments to any embedded parameters in the SQL</param>
/// <returns>A collection of POCO's as a List</returns>
List<TRet> Fetch<T1, T2, TRet>(Func<T1, T2, TRet> cb, string sql, params object[] args);
//
///执行多poco提取
///
///第一种POCO类型
///第二种POCO类型
///返回的列表为POCO类型
///用于连接POCO实例的回调函数,或用于自动猜测关系的null
///要执行的SQL查询
///SQL中任何嵌入参数的参数
///作为列表的POCO集合
列表获取(Func cb、字符串sql、参数对象[]args);
范例
db.Fetch<PupilCache, KeyValuePoco, PupilCache>((pc, kv) => pc.Properties.Add(kv.Key, kv.Value), "query");
db.Fetch((pc,kv)=>pc.Properties.Add(kv.Key,kv.Value),“查询”);
这里是PetaPoco维护者。是的,这应该可以使用fetch方法实现,您为该方法提供了一个回调来填充Poco关系。但是,您需要提供Poco,以便PetaPoco可以将DB中的键值列映射到Poco(必需)
看到这个了吗
/// <summary>
/// Perform a multi-poco fetch
/// </summary>
/// <typeparam name="T1">The first POCO type</typeparam>
/// <typeparam name="T2">The second POCO type</typeparam>
/// <typeparam name="TRet">The returned list POCO type</typeparam>
/// <param name="cb">A callback function to connect the POCO instances, or null to automatically guess the relationships</param>
/// <param name="sql">The SQL query to be executed</param>
/// <param name="args">Arguments to any embedded parameters in the SQL</param>
/// <returns>A collection of POCO's as a List</returns>
List<TRet> Fetch<T1, T2, TRet>(Func<T1, T2, TRet> cb, string sql, params object[] args);
//
///执行多poco提取
///
///第一种POCO类型
///第二种POCO类型
///返回的列表为POCO类型
///用于连接POCO实例的回调函数,或用于自动猜测关系的null
///要执行的SQL查询
///SQL中任何嵌入参数的参数
///作为列表的POCO集合
列表获取(Func cb、字符串sql、参数对象[]args);
范例
db.Fetch<PupilCache, KeyValuePoco, PupilCache>((pc, kv) => pc.Properties.Add(kv.Key, kv.Value), "query");
db.Fetch((pc,kv)=>pc.Properties.Add(kv.Key,kv.Value),“查询”);