zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    如果用 索引的话,这个太不方便了,草,
    nslocal notification
    夜半三更,
    别人写的 代码,
    账目
    view 关于 controller的代理
    浅谈GFC
    浅谈IFC
    浅谈BFC
    JS ES6中的箭头函数(Arrow Functions)使用
  • 原文地址:https://www.cnblogs.com/love-zf/p/6438339.html
Copyright © 2011-2022 走看看