开发者

LINQ + WCF + Transactions

I have a relatively simple use case which is failing. Consider the following code:开发者_开发百科

[OperationBehavior(TransactionScopeRequired = true)]
public IEnumerable<StatusRecord> ReadActive(int contactID, bool isActive)
{
  var result = from n in ORM.Default.Table<StatusRecord>()
                where n.lng_contact_id == contactID && n.dte_effective_end == null
                select n;

  return result;
}

This is using a custom LINQ-SQL provider of our own evil origins. Normally this type of call works great, but when using it from a DTC Transacted WCF call, it hangs. My theory is that the serialization of the result into an array somehow occurs outside the transaction scope and therefore hangs. Furthermore, my theory is supported by the fact that changing the line

return result;

to

return result.ToArray();

makes things work. Although I am pleased to have a workaround, it seems there is a better way to get this behaving. Please advise. Thank you!


Don't use deffered execution in WCF operation. You have to execute your query before you returning result - that is what you did in result.ToArray().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜