Google Analytics İzleme

29 Aralık 2011

entity framework ve automapper kullanımı; DTO'dan Entity'e atama


Örnek Yazım:


public void Update(BusinessObject.Setting pSetting)
{


            using (var dbContext = new AppDBEntities())
            {
                EFModel.OKFormSetting record = (from r in dbContext.OKFormSetting
                              where r.SettingCode.Equals(pSetting.SettingCode)
                              select r).FirstOrDefault();

                Mapper.CreateMap<BusinessObject.Setting, EFModel.OKFormSetting>()
                    .ForMember(dest => dest.EntityKey, opt => opt.Ignore());
                   
                record = Mapper.Map<BusinessObject.Setting, EFModel.OKFormSetting>(pSetting,record);

                Mapper.AssertConfigurationIsValid();


               dbContext.SaveChanges();

            }
}

Kaynak:
http://groups.google.com/group/automapper-users/browse_thread/thread/24a90f22323a27bc?fwc=1&pli=1
http://www.devtrends.co.uk/blog/stop-using-automapper-in-your-data-access-code


Hiç yorum yok: