Beispiel #1
0
        private static EntityConnection GetDbConnection(DatabaseAccessRequest request)
        {
            request.ProviderName = DatabaseProviderType.EntityClient;
            var assembly = typeof(T).Assembly;
            var manifestResourceNames = assembly.GetManifestResourceNames();
            var metadata = new List <string>();

            manifestResourceNames.ToList().ForEach(resource =>
            {
                metadata.Add($@"res://*/{resource}");
            });
            var entityFrameworkDatabaseAccessRequest = new EntityFrameworkDatabaseAccessRequest(request)
            {
                Metadata = metadata.ToArray(),
                Assembly = assembly
            };
            var metadataWorkspace    = new MetadataWorkspace(entityFrameworkDatabaseAccessRequest.Metadata, new[] { entityFrameworkDatabaseAccessRequest.Assembly });
            var connectionString     = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
            var connectionStringInfo = new ConnectionStringInfo {
                ConnectionString = connectionString
            };
            var builder = new SqlConnectionStringBuilder(connectionStringInfo.ConnectionString)
            {
                MultipleActiveResultSets = true,
                WorkstationID            = request.WorkStationId
            };
            var sqlConnection = new SqlConnection(builder.ConnectionString);

            if (!string.IsNullOrEmpty(connectionStringInfo.UserName))
            {
                sqlConnection.Credential = new SqlCredential(connectionStringInfo.UserName, connectionStringInfo.SecurePassword);
            }
            return(new EntityConnection(metadataWorkspace, sqlConnection));
        }
Beispiel #2
0
        private static DbContextOptions GetDbConnection(DatabaseAccessRequest request)
        {
            DbContextOptionsBuilder optionsBuilder = new DbContextOptionsBuilder();

            var connectionString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;

            optionsBuilder.UseSqlServer(connectionString);
            optionsBuilder.UseLoggerFactory(GetLoggerFactory());
            return(optionsBuilder.Options);
        }
Beispiel #3
0
 public EntityFrameworkDatabaseAccessRequest(DatabaseAccessRequest databaseAccessRequest)
 {
     DatabaseIdentifier = databaseAccessRequest.DatabaseIdentifier;
     ProviderName       = databaseAccessRequest.ProviderName;
     WorkStationId      = databaseAccessRequest.WorkStationId;
 }
Beispiel #4
0
 protected AtlasDbContext(DatabaseAccessRequest request)
     : base(GetDbConnection(request), true)
 {
     // ReSharper disable once UnusedVariable - hack to include assembly in output folder
     var hack = typeof(System.Data.Entity.SqlServer.SqlProviderServices);
 }