我如何使用ado.net dataservice检查是否存在行?

时间:2009-04-06 22:38:58

标签: ado.net dataservice

var svc = new LocationDataServiceContext();
var q = from c in svc.LocationTable
                      where c.ID == int.Parse(location.ID)
                      select c;
if (q.ToArray().Length == 0)

有没有更简洁的方法来做到这一点?

1 个答案:

答案 0 :(得分:0)

是的,我相信......

    var svc = new LocationDataServiceContext();

    if (svc.LocationTable.SingleOrDefault(c => c.ID == int.Parse(location.ID) != null))
    {

    }

我认为有一种Exist()方法......但我猜不是。