forked from npgsql/npgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNpgsqlEFConnection.cs
More file actions
44 lines (36 loc) · 1.63 KB
/
NpgsqlEFConnection.cs
File metadata and controls
44 lines (36 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Data.Common;
using System.Data.SqlClient;
using JetBrains.Annotations;
using Microsoft.Data.Entity;
using Microsoft.Data.Entity.Infrastructure;
using Microsoft.Data.Entity.Relational;
using Microsoft.Data.Entity.Utilities;
using Microsoft.Framework.Logging;
using Npgsql;
namespace Npgsql.EntityFramework7
{
public class NpgsqlEFConnection : RelationalConnection, INpgsqlEFConnection
{
private readonly ILoggerFactory _loggerFactory;
public NpgsqlEFConnection([NotNull] IDbContextOptions options, [NotNull] ILoggerFactory loggerFactory)
: base(options, loggerFactory)
{
Check.NotNull(loggerFactory, nameof(loggerFactory));
_loggerFactory = loggerFactory;
}
// TODO: Consider using DbProviderFactory to create connection instance
// Issue #774
protected override DbConnection CreateDbConnection() => new NpgsqlConnection(ConnectionString);
public virtual INpgsqlEFConnection CreateMasterConnection()
{
var builder = new NpgsqlConnectionStringBuilder { ConnectionString = ConnectionString };
// TODO use clone connection method once implimented see #1406
var optionsBuilder = new DbContextOptionsBuilder();
optionsBuilder.UseNpgsql(builder.ConnectionString).CommandTimeout(CommandTimeout);
return new NpgsqlEFConnection(optionsBuilder.Options, _loggerFactory);
}
}
}