我正在使用Entity Framework 5和Code First Migrations.我有一个DataStore类派生自DbContext:
public class DataStore : DbContext, IDataStore
{
public int UserID { get; private set; }
public DataStore(int userId, string connectionString) : base(connectionString)
{
UserID = userId;
}
public virtual IDbSet<User> Users { get; set; }
// Rest of code here
}
Run Code Online (Sandbox Code Playgroud)
还有一个创建类实例的工厂DataStore类:
public class DataStoreFactory : Disposable, IDataStoreFactory
{
private DataStore _database;
private int _userId;
private string _connectionString;
public DataStoreFactory(int userId, string connectionString)
{
_userId = userId;
_connectionString = …Run Code Online (Sandbox Code Playgroud) c# entity-framework dependency-injection unity-container asp.net-mvc-4