linq相关

这两天遇见点笑不出来的bug,真是服了,不知道咋写,瞎写的我真棒啊。

1、页面报错Exception: New transaction is not allowed because there are other threads running in the session,是在这样的场景下面:

var query=xxx.table.where();

foreach(var item in query)

{

 _xxx.delete(item);

}

主要原因是我们的foreach的循环时,我们不能在同一个连接中同时Reader读数据,又同时做Update,它还没有读完。这时你需要把这个集合对象转换成Array或List<T>,需要var query=xxx.table.where().tolist();

2、tolist的query,就算没有数据也不等于null,要用count判断是否有值,

我这两年都干了啥,唉,笑不出来.jpg

原文地址:https://www.cnblogs.com/jksun/p/11435037.html