Using EF 5 in Custom Module

Topics: Customizing Orchard, Writing modules
Jun 17, 2013 at 7:05 AM
Edited Jun 17, 2013 at 7:09 AM
Hi,

Anyone worked on a module that uses Entity Framework 5?

I've creating a module that utilize EF5 inside the controller but I'm getting a "System.NotSupportedException: MySQL Connector/Net does not currently support distributed transactions." error.

What's the best implementation for using EF5 in Orchard?

Thanks and regards,
Developer
Jun 17, 2013 at 12:43 PM
Edited Jun 17, 2013 at 12:44 PM
Make sure you supress the ambient Transaction around your EF context.
using (new TransactionScope(TransactionScopeOption.Suppress)) {
    // Your data access code here 
}
Developer
Jun 17, 2013 at 11:57 PM
Edited Jun 17, 2013 at 11:58 PM
Nick is correct - you need to suppress the scope. Otherwise your transaction will get elevated to MSDTC and you're more or less screwed or at best will have a huge perf hit. Also please not this workaround is needed for Orchard <= 1.6 only - it will be a non-issue in the soon-to-arrive 1.7 version.
Jun 25, 2013 at 4:13 AM
Cool this works perfectly.

Thanks Jetski5822 and more power.
Jun 25, 2013 at 7:39 AM
pszmyd wrote:
Nick is correct - you need to suppress the scope. Otherwise your transaction will get elevated to MSDTC and you're more or less screwed or at best will have a huge perf hit. Also please not this workaround is needed for Orchard <= 1.6 only - it will be a non-issue in the soon-to-arrive 1.7 version.
pszmyd:
Do you mean that from 1.7 we will not need the ambient transaction around the ef context ? That would be so cool.