LINQ to SQL always uses default transactions?

I'm doing security analysis of the code, but I'm having trouble finding (in the documentation) if LINQ always uses transactions when it does the desired operation, or if I need to specify some special attribute / parameter.

Does anyone know this?

+3


source to share


3 answers


LINQ, in general, just gives some information to the query provider about the code that defines the LINQ query. The query provider can do whatever it wants as its implementation. He may or may not use a transaction. You could write your own request provider that wraps each request in a transaction block if you wanted, or you could write one that didn't. You will need to look at the documentation (or do some testing) for any specific query provider you are using (and possibly a specific query, as it can vary from query to query) to see how the query provider translates LINQ expressions to SQL ...



+4


source


The correct answer to your question is NO.

With that said, you asked the wrong question. LINQ is for querying data, and queries don't use transactions. Your provider you are using in LINQ can change whether it ignores, skips, or waits for locked records during a query, but this is not part of LINQ.



Entity Framework, however, with a data provider that supports transactions, will do transactions by default, which is probably what you wanted to ask.

+1


source


No, this is not an atomic transaction, as you saw in the STARTUP PROCEDURE, which starts with BEGIN TRANS. You will need to get hold of the System.Transactions namespace and wrap your use block in a transaction.

0


source







All Articles