Sanjay Maharjan
Sanjay Maharjan

Reputation: 671

linq join causing very slow performance / correct way to optimize it

I have join in linq as below

IEnumerable < UserATrailViewModel > v1 = from u in useratrailbusiness.GetAllUsers().AsQueryable()
join u1 in userPackageAtrailBusiness.GetAllUsers().AsQueryable()
on u.Uid equals u1.Uid into t1
from subpet in t1.DefaultIfEmpty()
orderby u.CreatedDate descending

select new UserATrailViewModel {

    UserATID = u.UserATID,
    Uid = u.Uid,
    RoleId = u.RoleId,

    FirstName = Md5Decryption.Decrypt(u.FirstName),
    LastName = Md5Decryption.Decrypt(u.LastName),
    Email = u.Email,
    UserName = u.UserName,
    CreatedDate = u.CreatedDate,
    IsActive = u.IsActive,
    CreatedBy = u.CreatedBy,
    ModifiedDate = u.ModifiedDate,
    ModifiedBy = u.ModifiedBy,
    //UniqueGuid = u.UniqueGuid,
    CompanyName = Md5Decryption.Decrypt(u.CompanyName),
    Country = Md5Decryption.Decrypt(u.Country),

    State = Md5Decryption.Decrypt(u.State),
    City = Md5Decryption.Decrypt(u.City),

    Address1 = Md5Decryption.Decrypt(u.Address1),
    Address2 = Md5Decryption.Decrypt(u.Address2),
    PhoneNo = Md5Decryption.Decrypt(u.PhoneNo),
    MobileNo = Md5Decryption.Decrypt(u.MobileNo),
    SrvDTStamp = u.SrvDTStamp,
    ClientCountry = u.ClientCountry,
    App_User = u.App_User,
    Audit_Action = u.Audit_Action,
    FullName = Md5Decryption.Decrypt(u.FirstName) + " " + Md5Decryption.Decrypt(u.LastName),
    ContactNo = Md5Decryption.Decrypt(u.PhoneNo) + " , " + Md5Decryption.Decrypt(u.MobileNo),

    PackageName = (subpet == null ? String.Empty : subpet.PackageName),
};

it is extremely slow as it takes 18 to 24 seconds to fetch the data even for 40 to 50 records. How can I make it faster as it is very much slow.I am not sure whether it is right way to get these data or not.so Any other alternative to this is appreciated as well which can make the process much faster.

Upvotes: 0

Views: 932

Answers (1)

Milnev
Milnev

Reputation: 105

You could start by moving all the calls to the Md5Decryption.Decrypt() method to the UserATrailViewModel class, either in the constructor or in custom setters. That will make your query more simple as you don't really want the database to do the decrypting.

Upvotes: 1

Related Questions