1+ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
2+
3+ using System ;
4+ using System . Data . Jet ;
5+ using System . Data . OleDb ;
6+ using EntityFrameworkCore . Jet . Infrastructure ;
7+ using JetBrains . Annotations ;
8+ using EntityFrameworkCore . Jet . Utilities ;
9+
10+ // ReSharper disable once CheckNamespace
11+ namespace Microsoft . EntityFrameworkCore
12+ {
13+ /// <summary>
14+ /// Jet specific OLE DB extension methods for <see cref="DbContextOptionsBuilder" />.
15+ /// </summary>
16+ public static class JetOleDbDbContextOptionsBuilderExtensions
17+ {
18+ #region Connection String
19+
20+ /// <summary>
21+ /// Configures the context to connect to a Microsoft Jet database using OLE DB.
22+ /// </summary>
23+ /// <param name="optionsBuilder"> The builder being used to configure the context. </param>
24+ /// <param name="fileNameOrConnectionString"> The file name or OLE DB connection string of the database to connect
25+ /// to. In case the connection string does not specify an Jet/ACE provider (OLE DB), the highest version of all
26+ /// compatible installed ones is being used. </param>
27+ /// <param name="jetOptionsAction">An optional action to allow additional Jet specific configuration.</param>
28+ /// <returns> The options builder so that further configuration can be chained. </returns>
29+ public static DbContextOptionsBuilder < TContext > UseJetOleDb < TContext > (
30+ [ NotNull ] this DbContextOptionsBuilder < TContext > optionsBuilder ,
31+ [ NotNull ] string fileNameOrConnectionString ,
32+ [ CanBeNull ] Action < JetDbContextOptionsBuilder > jetOptionsAction = null )
33+ where TContext : DbContext
34+ => optionsBuilder . UseJet ( fileNameOrConnectionString , DataAccessProviderType . OleDb , jetOptionsAction ) ;
35+
36+ /// <summary>
37+ /// Configures the context to connect to a Microsoft Jet database using OLE DB.
38+ /// </summary>
39+ /// <param name="optionsBuilder"> The builder being used to configure the context. </param>
40+ /// <param name="fileNameOrConnectionString"> The file name or OLE DB connection string of the database to connect
41+ /// to. In case the connection string does not specify an Jet/ACE provider (OLE DB), the highest version of all
42+ /// compatible installed ones is being used. </param>
43+ /// <param name="jetOptionsAction">An optional action to allow additional Jet specific configuration.</param>
44+ /// <returns> The options builder so that further configuration can be chained. </returns>
45+ public static DbContextOptionsBuilder UseJetOleDb (
46+ [ NotNull ] this DbContextOptionsBuilder optionsBuilder ,
47+ [ NotNull ] string fileNameOrConnectionString ,
48+ [ CanBeNull ] Action < JetDbContextOptionsBuilder > jetOptionsAction = null )
49+ => optionsBuilder . UseJet ( fileNameOrConnectionString , DataAccessProviderType . OleDb , jetOptionsAction ) ;
50+
51+ #endregion
52+
53+ #region Connection
54+
55+ /// <summary>
56+ /// Configures the context to connect to a Microsoft Jet database using OLE DB.
57+ /// </summary>
58+ /// <typeparam name="TContext"> The type of context to be configured. </typeparam>
59+ /// <param name="optionsBuilder"> The builder being used to configure the context. </param>
60+ /// <param name="connection">
61+ /// An existing <see cref="OleDbConnection" /> to be used to connect to the database. If the connection is in
62+ /// the open state then EF will not open or close the connection. If the connection is in the closed state
63+ /// then EF will open and close the connection as needed.
64+ /// </param>
65+ /// <param name="jetOptionsAction">An optional action to allow additional Jet specific configuration.</param>
66+ /// <returns> The options builder so that further configuration can be chained. </returns>
67+ public static DbContextOptionsBuilder < TContext > UseJetOleDb < TContext > (
68+ [ NotNull ] this DbContextOptionsBuilder < TContext > optionsBuilder ,
69+ [ NotNull ] OleDbConnection connection ,
70+ [ CanBeNull ] Action < JetDbContextOptionsBuilder > jetOptionsAction = null )
71+ where TContext : DbContext
72+ {
73+ Check . NotNull ( optionsBuilder , nameof ( optionsBuilder ) ) ;
74+ Check . NotNull ( connection , nameof ( connection ) ) ;
75+
76+ return optionsBuilder . UseJet ( connection , jetOptionsAction ) ;
77+ }
78+
79+ /// <summary>
80+ /// Configures the context to connect to a Microsoft Jet database using OLE DB.
81+ /// </summary>
82+ /// <param name="optionsBuilder"> The builder being used to configure the context. </param>
83+ /// <param name="connection">
84+ /// An existing <see cref="OleDbConnection" /> to be used to connect to the database. If the connection is in
85+ /// the open state then EF will not open or close the connection. If the connection is in the closed state
86+ /// then EF will open and close the connection as needed.
87+ /// </param>
88+ /// <param name="jetOptionsAction">An optional action to allow additional Jet specific configuration.</param>
89+ /// <returns> The options builder so that further configuration can be chained. </returns>
90+ public static DbContextOptionsBuilder UseJetOleDb (
91+ [ NotNull ] this DbContextOptionsBuilder optionsBuilder ,
92+ [ NotNull ] OleDbConnection connection ,
93+ [ CanBeNull ] Action < JetDbContextOptionsBuilder > jetOptionsAction = null )
94+ {
95+ Check . NotNull ( optionsBuilder , nameof ( optionsBuilder ) ) ;
96+ Check . NotNull ( connection , nameof ( connection ) ) ;
97+
98+ return optionsBuilder . UseJet ( connection , jetOptionsAction ) ;
99+ }
100+
101+ #endregion
102+ }
103+ }
0 commit comments