首页 > 代码库 > EF将IEnumerable<T>类型转换为Dictionary<T,T>类型

EF将IEnumerable<T>类型转换为Dictionary<T,T>类型

x

无标题

#region 博客Code {DBEntities}生成EFModel的时候自己命名的
using ({DBEntities} db = new { DBEntities }())
{
    var que = (from c in db.CollectItem select c).ToList();
    List<Dictionary<string, object>> retList = new List<Dictionary<string, object>>();
    Dictionary<string, object> retDic = new Dictionary<string, object>();
    PropertyInfo[] properArr = null;
    foreach (var q in que)
    {
        retDic = new Dictionary<string, object>();
        properArr = q.GetType().GetProperties();
        foreach (PropertyInfo p_info in properArr)
        {
            retDic.Add(p_info.Name, p_info.GetValue(q));
        }
        retList.Add(retDic);
    }
    Dictionary<string, string> resultDic = new Dictionary<string, string>();
    resultDic.Add("ret", "1");
    JSONParameters jp = new JSONParameters { UseUTCDateTime = false };
    resultDic.Add("list", JSON.Instance.ToJSON(retList, jp));
    return JSON.Instance.ToJSON(resultDic, jp);
}
#endregion

 

x

EF将IEnumerable<T>类型转换为Dictionary<T,T>类型