c# - Entity Framework performance problems -
i'm having problem below query taking around 700ms execute. it's in loop , gets called 100+ times it's taking forever.
model:
public class releasedates { public int id { get; set; } public string moviename { get; set; } public string country { get; set; } public datetime releasedate { get; set; } public string alternatesource { get; set; } }
query:
public async task<list<releasedates>> getreleasedatesasync(string moviename) { return await db.releasedates.where(x => x.moviename == moviename && string.isnullorempty(x.alternatesource)).tolistasync(); }
any suggestions how speed up?
get rid of loop. that's problem. you're sending lot of queries database.
store movie names you're searching in list , contains there.
public async task<list<releasedates>> getreleasedatesasync(list<string> movienames) { //movie names you're searching - movienames return await db.releasedates.where(x => movienames.contains(x.moviename) && string.isnullorempty(x.alternatesource)).tolistasync(); }
if want release dates "ant moon", "godzippa", "superwan", list contain these strings , it.
some further reading: http://blogs.msdn.com/b/alexj/archive/2009/03/26/tip-8-writing-where-in-style-queries-using-linq-to-entities.aspx
Comments
Post a Comment