public CardViewModel Read(int id) { try { CardViewModel result = new CardViewModel(); using (var context = new CardHolderContext()) { result = (from crd in context.Cards where crd.CardId == id join cat in context.CategoryMasters on crd.CategoryId equals cat.CategoryId join con in context.ContactDetails on crd.CardId equals con.CardId select new CardViewModel() { CardDetails = crd, Category = cat, Contact = con } ).FirstOrDefault(); if (result == null) throw new Exception("Invalid id"); result.SocialMedia = new List(); result.SocialMedia = (from soc in context.SocialMedia where soc.CardId == id select soc ).ToList(); } return result; } catch (Exception ex) { throw new Exception(ex.Message); } }