Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add IsRelational extension for DatabaseFacade #19521

Merged
merged 3 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,19 @@ public static void SetCommandTimeout([NotNull] this DatabaseFacade databaseFacad
public static string GenerateCreateScript([NotNull] this DatabaseFacade databaseFacade)
=> databaseFacade.GetRelationalService<IRelationalDatabaseCreator>().GenerateCreateScript();

/// <summary>
/// <para>
/// Returns true if the database provider currently in use is a relational database.
/// </para>
/// </summary>
/// <param name="databaseFacade"> The facade from <see cref="DbContext.Database" />. </param>
/// <returns> True if a relational database provider is being used; false otherwise. </returns>
public static bool IsRelational([NotNull] this DatabaseFacade databaseFacade)
{
var dependencies = ((IDatabaseFacadeDependenciesAccessor)databaseFacade).Dependencies;
WeihanLi marked this conversation as resolved.
Show resolved Hide resolved
return dependencies is IRelationalDatabaseFacadeDependencies;
WeihanLi marked this conversation as resolved.
Show resolved Hide resolved
}

private static IRelationalDatabaseFacadeDependencies GetFacadeDependencies(DatabaseFacade databaseFacade)
{
var dependencies = ((IDatabaseFacadeDependenciesAccessor)databaseFacade).Dependencies;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ namespace Microsoft.EntityFrameworkCore
{
public class RelationalDatabaseFacadeExtensionsTest
{
[ConditionalFact]
public void IsRelational_returns_if_relational()
WeihanLi marked this conversation as resolved.
Show resolved Hide resolved
{
var dbConnection = new FakeDbConnection("A=B");
var context = RelationalTestHelpers.Instance.CreateContext();
Assert.True(context.Database.IsRelational());
}


[ConditionalFact]
public void GetDbConnection_returns_the_current_connection()
{
Expand Down