COA.EnterpriseServices/COA.EnterpriseServices.DataAccess.EntityFramework/EntityDataAccess.cs

58 lines
1.3 KiB
C#
Raw Normal View History

2020-10-14 00:56:53 +00:00
using System;
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;
using System.Text;
namespace COA.EnterpriseServices.DataAccess.EntityFramework
{
2020-10-14 01:24:27 +00:00
public class EntityDataAccess<T> : IDataAccess<T> where T : class, IRecord
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())
{
context.Entry(item);
context.SaveChanges();
}
return true;
2020-10-14 00:56:53 +00:00
}
public ICollection<T> Get(int id)
{
2020-10-14 01:24:27 +00:00
using (var context = new QuickBaseContext())
{
return context
.Set<T>()
.Where(r => r.Id == id)
.ToList();
}
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
}
}
}