mirror of
https://github.com/bitwarden/server.git
synced 2025-07-14 22:27:32 -05:00
[SM-394] Secrets Manager (#2164)
Long lived feature branch for Secrets Manager Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com> Co-authored-by: cd-bitwarden <106776772+cd-bitwarden@users.noreply.github.com> Co-authored-by: CarleyDiaz-Bitwarden <103955722+CarleyDiaz-Bitwarden@users.noreply.github.com> Co-authored-by: Thomas Avery <tavery@bitwarden.com> Co-authored-by: Colton Hurst <colton@coltonhurst.com>
This commit is contained in:
19
src/Infrastructure.EntityFramework/EfExtensions.cs
Normal file
19
src/Infrastructure.EntityFramework/EfExtensions.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework;
|
||||
|
||||
public static class EfExtensions
|
||||
{
|
||||
public static T AttachToOrGet<T>(this DbContext context, Func<T, bool> predicate, Func<T> factory)
|
||||
where T : class, new()
|
||||
{
|
||||
var match = context.Set<T>().Local.FirstOrDefault(predicate);
|
||||
if (match == null)
|
||||
{
|
||||
match = factory();
|
||||
context.Attach(match);
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user