mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Code cleanup
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Kruzya.TelegramBot.Core.Extensions;
|
||||
|
||||
public static class DbContextExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Marks the entity as created.
|
||||
/// </summary>
|
||||
/// <param name="dbContext"></param>
|
||||
/// <param name="entity">Entity for marking as created.</param>
|
||||
[Obsolete("DbContextExtension.MarkAsCreated is obsolete, use DbSet<T>.Add instead")]
|
||||
public static void MarkAsCreated(this DbContext dbContext, object entity) =>
|
||||
dbContext.Entry(entity).State = EntityState.Added;
|
||||
|
||||
/// <summary>
|
||||
/// Marks the entity as deleted.
|
||||
/// </summary>
|
||||
/// <param name="dbContext"></param>
|
||||
/// <param name="entity">Entity for marking as deleted.</param>
|
||||
[Obsolete("DbContextExtension.MarkAsDeleted is obsolete, use DbSet<T>.Remove instead")]
|
||||
public static void MarkAsDeleted(this DbContext dbContext, object entity) =>
|
||||
dbContext.Entry(entity).State = EntityState.Deleted;
|
||||
|
||||
/// <summary>
|
||||
/// Marks the entity as modified.
|
||||
/// </summary>
|
||||
/// <param name="dbContext"></param>
|
||||
/// <param name="entity">Entity for marking as modified.</param>
|
||||
[Obsolete("DbContextExtension.MarkAsModified is obsolete, use DbContext.Update instead")]
|
||||
public static void MarkAsModified(this DbContext dbContext, object entity)
|
||||
{
|
||||
var entry = dbContext.Entry(entity);
|
||||
if (entry.State == EntityState.Added)
|
||||
return;
|
||||
|
||||
entry.State = EntityState.Modified;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user