2020-10-15 11:07:32 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using System;
|
2020-10-14 00:56:53 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-10-14 01:24:27 +00:00
|
|
|
|
using System.Linq;
|
2020-10-14 00:56:53 +00:00
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
|
|
|
|
|
namespace COA.EnterpriseServices.DataAccess.EntityFramework
|
|
|
|
|
{
|
2020-10-15 11:07:32 +00:00
|
|
|
|
public class EntityDataAccess<T> : IDataAccess<T> where T : class, IRecord, new()
|
2020-10-14 00:56:53 +00:00
|
|
|
|
{
|
|
|
|
|
public bool Add(T item)
|
|
|
|
|
{
|
2020-10-14 01:24:27 +00:00
|
|
|
|
using (var context = new QuickBaseContext())
|
|
|
|
|
{
|
|
|
|
|
context.Add(item);
|
|
|
|
|
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2020-10-14 00:56:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Update(T item)
|
|
|
|
|
{
|
2020-10-14 01:24:27 +00:00
|
|
|
|
using (var context = new QuickBaseContext())
|
|
|
|
|
{
|
2020-10-15 11:07:32 +00:00
|
|
|
|
var entry = context.Entry(item);
|
|
|
|
|
|
|
|
|
|
entry.State = EntityState.Modified;
|
|
|
|
|
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 00:56:53 +00:00
|
|
|
|
public ICollection<T> Get(Expression<Func<T, bool>> query)
|
|
|
|
|
{
|
2020-10-14 01:24:27 +00:00
|
|
|
|
using (var context = new QuickBaseContext())
|
|
|
|
|
{
|
|
|
|
|
return context
|
|
|
|
|
.Set<T>()
|
|
|
|
|
.Where(query)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
2020-10-14 00:56:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|