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

49 lines
1.1 KiB
C#

using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
namespace COA.EnterpriseServices.DataAccess.EntityFramework
{
public class EntityDataAccess<T> : IDataAccess<T> where T : class, IRecord, new()
{
public bool Add(T item)
{
using (var context = new QuickBaseContext())
{
context.Add(item);
context.SaveChanges();
}
return true;
}
public bool Update(T item)
{
using (var context = new QuickBaseContext())
{
var entry = context.Entry(item);
entry.State = EntityState.Modified;
context.SaveChanges();
}
return true;
}
public ICollection<T> Get(Expression<Func<T, bool>> query)
{
using (var context = new QuickBaseContext())
{
return context
.Set<T>()
.Where(query)
.ToList();
}
}
}
}