My current respository is as follows , please suggest , i am currently using LINQ2SQL Data context per insert/delele/update
namespace Lib.Repository
{
public class MotorRenewalDataRepository
{
public MotorRenewalDataRepository()
{
}
public MotorRenewalData GetByID(long id)
{
using(var _context=DatabaseFactory.Create(false))
{
return _context.MotorRenewalDatas.Where(p => p.MotorRenewalDataID == id).FirstOrDefault();
}
}
public MotorRenewalData Insert(MotorRenewalData entity)
{
using (var _context = DatabaseFactory.Create(false))
{
_context.MotorRenewalDatas.InsertOnSubmit(entity);
_context.SubmitChanges();
return entity;
}
}
public void Update(MotorRenewalData entity)
{
using (var _context = DatabaseFactory.Create(true))
{
var dbEntity = _context.MotorRenewalDatas.Where(p => p.MotorRenewalDataID == entity.MotorRenewalDataID)
.FirstOrDefault();
Common.CopyObject<MotorRenewalData>(entity, dbEntity);
_context.SubmitChanges();
}
}
}
}