我有这个代码:
list = _dataContext.myTable
.Where(row => row.Label.Contains(myText))
.OrderBy(row => row.Label)
.Select(row => new MyClass
{
Field1 = row.Field1,
Field2 = row.Field2,
Field3 = row.Field3
}).ToList<IMyClass>();
list = _dataContext.myTable
.OrderBy(row => row.Label)
.Select(row => new MyClass
{
Field1 = row.Field1,
Field2 = row.Field2,
Field3 = row.Field3
}).ToList<IMyClass>();
如您所见,我有重复的代码。然后我这样做:
private List<IMyClass> CreateObject(IOrderedQueryable<myTable> list)
{
return list.Select(row => new MyClass
{
Field1 = row.Field1,
Field2 = row.Field2,
Field3 = row.Field3
}).ToList<IMyClass>();
}
result = _dataContext.myTable
.Where(row => row.Label.Contains(myText))
.OrderBy(row => row.Label);
var finalList = CreateObject(result);
当我这样做时,“Linq 2 SQL profiler”给了我这个警告:
在多线程中使用单个数据上下文可能是一个错误。
我只有在使用该CreateObject
方法时才有这个
有任何想法吗?