惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
V
Visual Studio Blog
Last Week in AI
Last Week in AI
Stack Overflow Blog
Stack Overflow Blog
The GitHub Blog
The GitHub Blog
Recent Announcements
Recent Announcements
博客园 - Franky
D
DataBreaches.Net
B
Blog
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
人人都是产品经理
人人都是产品经理
WordPress大学
WordPress大学
P
Proofpoint News Feed
J
Java Code Geeks
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Martin Fowler
Martin Fowler
月光博客
月光博客
宝玉的分享
宝玉的分享
Engineering at Meta
Engineering at Meta
阮一峰的网络日志
阮一峰的网络日志
F
Fortinet All Blogs
博客园 - 【当耐特】

博客园 - JJ.Net

正在还原 PowerDesign Comment显示 with(nolock) for xml path 某个sql帖子的答题 JQuery hide JQuery tr 循环,删除td JQuery Disabled QueryString大小设置 Silverlight HelloWorld MVC控制器跳转 JQuery选择器倒数 最后一行所有td加粗 Linq之OrderBy 循环初始化主从表数据 JQuery之Trim List<T>根据条件直接修改 JQuery选择器之has Sqlserver模拟Sequence
List自增Identity列
JJ.Net · 2015-03-23 · via 博客园 - JJ.Net
/// <summary>
    /// 转换实体类列表,增加自增列
    /// </summary>
    /// <typeparam name="T">原始实体类</typeparam>
    /// <typeparam name="U">目标实体类</typeparam>
    public class Class1<T,U>
    {
        /// <summary>
        /// 增加自增列
        /// </summary>
        /// <param name="list">原实体类列表</param>
        /// <param name="intIndentityColumnName">自增列名</param>
        /// <param name="initialValue">自增初始值</param>
        /// <returns></returns>
        public IList<U> AddIntIndentityColumn(IList<T> list, string intIndentityColumnName, int initialValue)
        {
            IList<U> listU = new List<U>();
            Type type = typeof(T);
            Type typeU = typeof(U);
            PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            int i = initialValue;
            foreach (T t in list)
            {                
                Type coltype = t.GetType();
                object object_u = Activator.CreateInstance(typeU);
                foreach (PropertyInfo p in props)
                {                    
                    object o = t.GetType().GetProperty(p.Name).GetValue(t, null);
                    object_u.GetType().GetProperty(p.Name).SetValue(object_u,o,null);
                }
                ++i;
                object_u.GetType().GetProperty(intIndentityColumnName).SetValue(object_u, i, null);
                listU.Add((U)object_u);
            }            
            return listU;
        }
    }