接上次,考虑到转DataTable实际性能问题,我把本地LINQ复杂对象不转成DataTable,仅去掉中间的复杂对象.
这样List<TEntity>就可以在WebService中传递了.同样抛砖引玉:-)
1
public static List<TEntity> ToGeneralList<TEntity>(this IList<TEntity> list) where TEntity : IMyCustomObject
2
{
3
Type type = typeof(TEntity);
4
System.Reflection.PropertyInfo[] infos = type.GetProperties();
5
foreach (System.Reflection.PropertyInfo info in infos)
6
{
7
if (info.GetCustomAttributes(typeof(System.Data.Linq.Mapping.ColumnAttribute), false).Length < 1)
8
{
9
if (info.CanWrite)
10
{
11
foreach (TEntity entity in list)
12
{
13
info.SetValue(entity, null, null);
14
}
15
}
16
}
17
}
18
19
return (List<TEntity>)list;
20
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

实际转换102000条数的表[12列.含三个复杂对象],设置所需时间106毫秒.