I am trying to port this class to the EF core:
https://github.com/mehdime/DbContextScope/blob/master/Mehdime.Entity/Implementations/DbContextScope.cs
However, I have this problem:
Error CS0246: the type name or namespace name 'IObjectContextAdapter' could not be found (do you miss the use directive or assembly link?) (CS0246) (Mehdime.Entity)
and this:
Error CS0246: ObjectStateEntry type or namespace name cannot (do you miss the use directive or assembly reference?) (CS0246) (Mehdime.Entity)
All nuget packages are already included.
using System; using System.Collections; using System.Data; using System.Linq; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; namespace Mehdime.Entity { public class DbContextScope : IDbContextScope { private bool _disposed; private bool _readOnly; private bool _completed; private bool _nested; private DbContextScope _parentScope; private DbContextCollection _dbContexts; public IDbContextCollection DbContexts { get { return _dbContexts; } } public DbContextScope(IDbContextFactory dbContextFactory = null) : this(joiningOption: DbContextScopeOption.JoinExisting, readOnly: false, isolationLevel: null, dbContextFactory: dbContextFactory) { } public DbContextScope(bool readOnly, IDbContextFactory dbContextFactory = null) : this(joiningOption: DbContextScopeOption.JoinExisting, readOnly: readOnly, isolationLevel: null, dbContextFactory: dbContextFactory) { } public DbContextScope(DbContextScopeOption joiningOption, bool readOnly, IsolationLevel? isolationLevel, IDbContextFactory dbContextFactory = null) { if (isolationLevel.HasValue && joiningOption == DbContextScopeOption.JoinExisting) throw new ArgumentException("Cannot join an ambient DbContextScope when an explicit database transaction is required. When requiring explicit database transactions to be used (ie when the 'isolationLevel' parameter is set), you must not also ask to join the ambient context (ie the 'joinAmbient' parameter must be set to false)."); _disposed = false; _completed = false; _readOnly = readOnly; _parentScope = GetAmbientScope(); if (_parentScope != null && joiningOption == DbContextScopeOption.JoinExisting) { if (_parentScope._readOnly && !this._readOnly) { throw new InvalidOperationException("Cannot nest a read/write DbContextScope within a read-only DbContextScope."); } _nested = true; _dbContexts = _parentScope._dbContexts; } else { _nested = false; _dbContexts = new DbContextCollection(readOnly, isolationLevel, dbContextFactory); } SetAmbientScope(this); } public int SaveChanges() { if (_disposed) throw new ObjectDisposedException("DbContextScope"); if (_completed) throw new InvalidOperationException("You cannot call SaveChanges() more than once on a DbContextScope. A DbContextScope is meant to encapsulate a business transaction: create the scope at the start of the business transaction and then call SaveChanges() at the end. Calling SaveChanges() mid-way through a business transaction doesn't make sense and most likely mean that you should refactor your service method into two separate service method that each create their own DbContextScope and each implement a single business transaction.");
source share