I am using EF6 and I have a query that selects only one entity from the database but with including all of the related entities. I am selecting only one using FirstOrDefault() method but sometimes this exception appears
System.Data.SqlClient.SqlException (0x80131904): Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction.
Here is the code that causes the issue
return All()
.Include(p => p.Location)
.Include(m => m.Bookings)
.Include(p => p.Links)
.Include(p => p.Links1)
.Include(p => p.Details)
.Include(p => p.Details.Select(x => x.Diagnostic))
.Include(p => p.Alerts)
.Include(p => p.Allergies)
.Include(p => p.Allergies.Select(x => x.List.ListCategory))
.Include(p => p.Links.Select(x => x.Link1))
.Include(p => p.Links1.Select(x => x.Link))
.FirstOrDefault(n => n.Id == id);
User contributions licensed under CC BY-SA 3.0