CrowderSoup
CrowderSoup

Reputation: 164

Slow Lambda Expression

Can anyone give me any pointers on how to make this run a bit faster?

return mb_entities.prospects.
         FirstOrDefault(x => x.address == person.Add &&
                x.homePhone == person.HPhone &&
                x.bizPhone == person.BPhone && 
                x.cellPhone == person.CPhone &&
                x.city == person.City &&
                x.state == person.State && 
                x.zip == person.Zip &&
                x.email == person.Email &&
                x.firstName == person.FName &&
                x.lastName == person.LName &&
                x.middleName == person.MName &&
                x.genCode == person.GC) ?? new prospect();

Right now it runs in between 160 and 180 Milliseconds. This would be ok if I didn't have to do it 1000 times.

Any tips would be greatly appreciated. Thanks!

Upvotes: 1

Views: 977

Answers (1)

usr
usr

Reputation: 171178

Create an index on the most selective columns (for example, on email, zip and lastname). This will speed it up. It should be one index on multiple columns.

You must have a lot of records in your table that it takes 160ms to execute this once. This is unusually long, even when no index is present.

Upvotes: 7

Related Questions