Using multiple DbContexts with their own transaction scopes
===

I need to access data from two different DbContexts at the same time, making sure each uses READ UNCOMMITTED for their queries.

How can you do this using Entity Framework? If I wrap each of the two queries in a TransactionScope, it tries to promote the transaction to MSDTC which isn't an option for us.

<!-- language: lang-css -->

	private static IEnumerable<Image> EnumerateSourceImages()
	{
		using (var dbContext = new SourceDbContext())
		{
			using (var transScope = new TransactionScope(
										TransactionScopeOption.RequiresNew,
										new TransactionOptions() {
												IsolationLevel = IsolationLevel.ReadUncommitted
											}
										)
								)
			{
				var imagesSourceQuery = dbContext.ImageDatas
										.AsNoTracking()
										.OrderBy(imageData => imageData.ImageID)
				foreach (var image in imagesSourceQuery)
				{
					yield return image;
				}
				transScope.Complete();
			}
		}
	}
	private static IEnumerable<Image> EnumerateDestinationImages()
	{
		using (var dbContext = new DestinationDbContext())
		{
			using (var transScope = new TransactionScope(
										TransactionScopeOption.RequiresNew,
										new TransactionOptions() {
												IsolationLevel = IsolationLevel.ReadUncommitted
											}
										)
								)
			{
				var imagesSourceQuery = dbContext.ImageDatas
									.AsNoTracking()
									.OrderBy(imageData => imageData.ImageID)
				foreach (var image in imagesSourceQuery)
				{
					yield return image;
				}
				transScope.Complete();
			}
		}
	}
	private static void main(string[] args){
	{
		IEnumerator<ItemImage> sourceImagesEnumerator = null;
		IEnumerator<ItemImage> destImagesEnumerator = null;
		try{
			sourceImagesEnumerator = EnumerateSourceImages().GetEnumerator();
			destImagesEnumerator = EnumerateDestinationImages().GetEnumerator();
			
			bool sourceHasMore = sourceImagesEnumerator.MoveNext();
			//Exception on next line about MSDTC Promotion
			bool destHasMore = destImagesEnumerator.MoveNext();
		} finally{
			if(sourceImagesEnumerator != null) sourceImagesEnumerator.Dispose();
			if(destImagesEnumerator != null) destImagesEnumerator.Dispose():
		}
	}

