c# - How do you assign a transaction with EF4 CodeFirst CTP5 without using TransactionScopes? -
i attempting perform functional tests against live database, make sure linq queries translating sql correctly. want using transactions, 1 functional test not affect another.
the problem is, cannot find way in api utilize transactions correctly. can retrieve new dbtransaction
via mydbcontext.database.connection.begintransaction()
, however, cannot find anyway use transaction.
all documentation can find begintransaction()
call, assign transaction object sqlcommand
via cmd.transaction
call command performing actions with. however, ef4 ctp5, there no way access sqlcommand
used queries.
thus, can't figure out how use transaction have begun begintransaction()
.
i not want use transactionscope
objects, because sql ce 4 not support them, , prefer use local database , not go across network. sql ce 4 support transactions retrieved via begintransaction()
, can't figure out how code first.
does have idea how this?
edit: after emails microsoft, seems
transactionscope()
calls meant primary way use transactions ef4. transactionscope
work sql ce have explicitely open database connection prior starting transaction, example [testmethod] public void my_sqlcescenario () { using (var context = new mysqlcemodelcontext()) //ß derived dbcontext { objectcontext objctx = ((iobjectcontextadapter)context).objectcontext; objctx.connection.open(); //ß open connection explicitly using (transactionscope tx = new transactionscope()) { var product = new product() { name = "vegemite" }; context.products.add(product); context.savechanges(); } objctx.connection.close(); //ß close when done! } }
maybe article on msdn might managing connections & transactions scroll down heading transactions , entity framework. that's start.
edit: here's better one: how to: manage transactions in entity framework
Comments
Post a Comment