LINQ2SQL DataLayer / Repository Suggestion

Posted by MindlessProgrammer on Stack Overflow See other posts from Stack Overflow or by MindlessProgrammer
Published on 2010-04-13T13:51:53Z Indexed on 2010/04/13 13:52 UTC
Read the original article Hit count: 272

Filed under:
|

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();

            }

        }

    }
}

© Stack Overflow or respective owner

Related posts about linq-to-sql

Related posts about c#