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);
All()
return, anIQueryable<T>
? What represents the scope of the DbContext thatAll()
and this code is relying on? One very ugly line of code with 12 joins or so may be where the exception comes up, but likely isn't the cause of the exception. – Steve Py Sep 7 '20 at 22:19