I have linq queries but many times I need to edit the properties with some external methods as I did above, it gives expected result but the problem is it look so dirty eventhough I need to edit one column, I need to reconstruct entire object body as you see below,
How can I make it better-looking?
Whats the most efficient of achieve this?
- Is there any way to not duplicate the context for editing context?
(I feel like 1 answer covers all these questions)
var query = (from islem in dbContext
join hasta in someEntity on islem.ID equals hasta.ID
select new
{
ID = islem.ID,
Phone=hasta.Phone,
BirthDate=islem.BirthDate,
MuayeneSonucu= islem.TBMuayeneSonucuId,
KurumKodu=islem.CreatedKurumKodu
}).AsEnumerable().Select(s => new myCustomModel()
{
ID = s.ID,
Birthdate=s.BirthDate.Date,
Phone=FormatPhone(s.Phone),
MuayeneSonucu = s.MuayeneSonucu,
KurumAdi = getKurumAdiByKod(Convert.ToInt32(s.KurumKodu))
// I need to recreate entire model because of this..
// and s.KayitTarihi.Date property ofc
}).AsQueryable().OrderByDescending(o => o.KayitTarihi);