mirror of
https://github.com/bitwarden/server.git
synced 2025-04-20 20:45:10 -05:00

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>
20 lines
477 B
C#
20 lines
477 B
C#
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;
|
|
}
|
|
}
|