public List<Contact> GetContact()
{
try
{
List<Contact> contacts = new List<Contact>();
using (var context = new V_ContactContext())
{
var data = context.V_ContactEntity.Where(x => x.ContactNumber != null);
//var data = context.ContactEntity.Where(x => x.ContactNumber != null).GroupBy(x => x.Id).Select(x => x.OrderByDescending(y => y.Version)).ToList().Select(x => x.FirstOrDefault()).ToList();
contacts = (from contact in data
select new Contact()
{
Id = contact.Id,
Version = contact.Version,
Code = contact.ContactNumber,
Gender = (Gender)contact.Gender,
LocalFirstName = contact.Name_Local,
LocalLastName = contact.FamilyName_Local,
EnglishFirstName = contact.Name_EN,
EnglishLastName = contact.FamilyName_EN,
EnglishNameAbbreviation = contact.NameAbbreviation_EN,
LocalNameAbbreviation = contact.NameAbbreviation_Local,
RelationShip = contact.RelationShip,
BusinessPhoneCode = contact.BusinessPhoneCode,
BusinessPhone = contact.BusinessPhone,
BusinessPhoneExtension = contact.BusinessPhoneExtension,
BusinessMobile = contact.BusinessMobile,
BusinessMobileCode = contact.BusinessMobileCode,
BusinessFax = contact.BusinessFax,
BusinessFaxCode = contact.BusinessFaxCode,
BusinessEmail = contact.BusinessEmail,
Note = contact.Note,
//TelePhone = data.Telephone,
//TelephoneExtension = data.TelephoneExtension,
//MobilePhone = data.MobilePhone,
//Fax = data.Fax,
//Email = data.Email,
//Remark = data.Remark,
localJobTitle = contact.JobTitle_local,
EnglishJobTitle = contact.JobTitle_En,
SuperiorID = contact.SuperiorID,
Source = contact.Source,
Birthday = contact.Birthday,
}).ToList();
return contacts;
}
}
catch (DbEntityValidationException exception)
{
throw exception.InnerException;
}
catch (Exception exception)
{
throw exception.InnerException;
}
} 这段代码怎么优化