Before update to NET 7
This commit is contained in:
52
BITKit/Scripts/EntityFramework/EntityFrameworkContext.cs
Normal file
52
BITKit/Scripts/EntityFramework/EntityFrameworkContext.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BITKit;
|
||||
|
||||
public interface IDatabaseContext<T> where T : class
|
||||
{
|
||||
void Add(T entity);
|
||||
UniTask AddAsync(T entity);
|
||||
void Remove(T entity);
|
||||
T[] GetArray();
|
||||
bool TrySearch(Func<T, bool> searchFactory, out T result);
|
||||
bool TrySearchArray(Func<T, bool> searchFactory, out T[] result);
|
||||
}
|
||||
|
||||
public abstract class EntityFrameworkContext<T>:DbContext ,IDatabaseContext<T> where T : class
|
||||
{
|
||||
protected DbSet<T> context { get; private set; }
|
||||
|
||||
public void Add(T entity)
|
||||
{
|
||||
context.Add(entity);
|
||||
SaveChanges();
|
||||
}
|
||||
|
||||
public async UniTask AddAsync(T entity)
|
||||
{
|
||||
await context.AddAsync(entity);
|
||||
await SaveChangesAsync();
|
||||
}
|
||||
|
||||
public void Remove(T entity)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public T[] GetArray()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool TrySearch(Func<T, bool> searchFactory, out T result)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool TrySearchArray(Func<T, bool> searchFactory, out T[] result)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
18
BITKit/Scripts/EntityFramework/MySQLContext.cs
Normal file
18
BITKit/Scripts/EntityFramework/MySQLContext.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging.Console;
|
||||
|
||||
namespace BITKit;
|
||||
|
||||
public class MySQLContext<T>:DbContext where T:class
|
||||
{
|
||||
protected readonly string _connectSql;
|
||||
protected DbSet<T> context { get; private set; }
|
||||
public MySQLContext(string connectSql) : base()
|
||||
{
|
||||
_connectSql = connectSql;
|
||||
}
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.UseMySQL("_connectSql");
|
||||
}
|
||||
}
|
@@ -4,14 +4,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BITKit;
|
||||
|
||||
public interface IDatabaseContext<T> where T : class
|
||||
{
|
||||
void Add(T entity);
|
||||
void Remove(T entity);
|
||||
T[] GetArray();
|
||||
bool TrySearch(Func<T, bool> searchFactory, out T result);
|
||||
bool TrySearchArray(Func<T, bool> searchFactory, out T[] result);
|
||||
}
|
||||
|
||||
|
||||
public class SqlLiteContext<T> : DbContext,IDatabaseContext<T> where T : class
|
||||
{
|
||||
|
Reference in New Issue
Block a user