Skip to content

Commit

Permalink
EF6: (I)DbContext.ExecuteWithDatabaseNullSemantics
Browse files Browse the repository at this point in the history
  • Loading branch information
jirikanda committed Apr 23, 2019
1 parent 771c60f commit 476efd5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
25 changes: 24 additions & 1 deletion Havit.Data.Entity6/DbContext.cs
Expand Up @@ -61,7 +61,7 @@ protected DbContext() : base("name=DefaultConnectionString")
/// }
/// </code>
/// </summary>
#pragma warning disable S3253 // "base()" constructor calls should not be explicitly made // JK: Chci ho zde pro přehlednost!
#pragma warning disable S3253 // "base()" constructor calls should not be explicitly made // JK: Chci ho zde pro přehlednost!
protected DbContext(DbContextDefaultDatabase dbContextDefaultDatabase) : base()
#pragma warning restore S3253 // "base()" constructor calls should not be explicitly made
{
Expand Down Expand Up @@ -319,6 +319,29 @@ public TResult ExecuteWithoutAutoDetectChanges<TResult>(Func<TResult> action)
}
}

/// <summary>
/// Provede akci s Configuration.UseDatabaseNullSemantics nastaveným na true, přičemž je poté Configuration.UseDatabaseNullSemantics nastaven na původní hodnotu.
/// </summary>
public TResult ExecuteWithDatabaseNullSemantics<TResult>(Func<TResult> action)
{
if (!Configuration.UseDatabaseNullSemantics)
{
try
{
Configuration.UseDatabaseNullSemantics = true;
return action();
}
finally
{
Configuration.UseDatabaseNullSemantics = false;
}
}
else
{
return action();
}
}

/// <summary>
/// Pouze pro existenci přetížení konstruktoru DbContextu, díky kterému se použije bezparametrický konstruktor předka.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Havit.Data.Entity6/Havit.Data.Entity6.csproj
Expand Up @@ -10,7 +10,7 @@
<!-- NuGet -->
<Import Project="../NuGet.targets"/>
<PropertyGroup>
<PackageVersion>2.0.1</PackageVersion>
<PackageVersion>2.0.2</PackageVersion>
<Description>HAVIT .NET Framework Extensions - Entity Framework 6 Extensions</Description>
</PropertyGroup>

Expand Down
5 changes: 5 additions & 0 deletions Havit.Data.Entity6/IDbContext.cs
Expand Up @@ -95,5 +95,10 @@ void SetEntityCollectionLoaded<TEntity>(TEntity entity, string propertyName, boo
/// Provede akci s AutoDetectChangesEnabled nastaveným na false, přičemž je poté AutoDetectChangesEnabled nastaven na původní hodnotu.
/// </summary>
TResult ExecuteWithoutAutoDetectChanges<TResult>(Func<TResult> action);

/// <summary>
/// Provede akci s Configuration.UseDatabaseNullSemantics nastaveným na true, přičemž je poté Configuration.UseDatabaseNullSemantics nastaven na původní hodnotu.
/// </summary>
TResult ExecuteWithDatabaseNullSemantics<TResult>(Func<TResult> action);
}
}

0 comments on commit 476efd5

Please sign in to comment.