, .. . , , count > 0, , - -. .
- , TransactionScope, ( ) :
using(var tran = new TransactionScope()) {
int count = OCall.Count();
if(count > 0) {
var call = Count.PopCall();
}
}
, . FirstOrDefault().
, PopCall - / SubmitChanges. , , , , .
SubmitChanges , , . PopCall :
public static OCall PopCall()
{
using(var tran = new TrasactionScope())
using (var db = new MyDataContext())
{
var fc = (from c in db.Calls where c.Called == false select c).FirstOrDefault();
OCall call = FillOCall(fc);
if (fc != null)
{
db.Calls.DeleteOnSubmit(fc);
db.SubmitChanges();
}
return call;
}
tran.Complete();
}
}
FirstOrDefault , . , UPDLOCK , LINQ-to-SQL .