首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

怎么调用 linq to datatable 创建的临时表

2012-04-01 
如何调用 linq to datatable 创建的临时表C# code #region Linq to datatable./// summary/// Linq to d

如何调用 linq to datatable 创建的临时表

C# code
 #region Linq to datatable.        /// <summary>        /// Linq to datatable.        /// </summary>        /// <typeparam name="T"></typeparam>        /// <param name="data"></param>        /// <returns></returns>        public static DataTable LinqToDataTable<T>(IEnumerable<T> data)        {            var dt = new DataTable();            // column names            PropertyInfo[] oProps = null;            // Could add a check to verify that there is an element 0            foreach (T rec in data)            {                // Use reflection to get property names, to create table, Only first time, others will follow                if (oProps == null)                {                    oProps = ((Type)rec.GetType()).GetProperties();                    foreach (PropertyInfo pi in oProps)                    {                        Type colType = pi.PropertyType;                        if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable<>)))                        {                            colType = colType.GetGenericArguments()[0];                        }                        dt.Columns.Add(new DataColumn(pi.Name, colType));                    }                }                DataRow dr = dt.NewRow(); foreach (PropertyInfo pi in oProps)                {                    dr[pi.Name] = pi.GetValue(rec, null) == null ? DBNull.Value : pi.GetValue(rec, null);                }                dt.Rows.Add(dr);            }            return dt;        }        #endregion



C# code
  #region 创建临时表            var _filter =            from q in mdc.WebSuite_Catalogs            where q.CatalogCancellation == false            orderby q.CatalogOrder            select            new           {               q.CatalogId,               q.CatalogRootId,               q.CatalogOrder,               q.CatalogName,               q.CatalogCode,               q.NavigationLicence,               q.CatalogPath           };            DataTable dt = LinqToDataTable(_filter);            #endregion


C# code
 public ActionResult CreateCategory(string Name, string status, string kind)        {                        //我该在这里如何写代码,去调用我的临时表??            return RedirectToAction("Index");        }        #endregion


[解决办法]
DataTable dt = LinqToDataTable(_filter);
调用这个dt?

热点排行