My EF 4.3.1 model has 200-odd tables. Initial startup is horrible, several minutes. A DotTrace-captured profile implies some terrible algorithm/scalability choices deep in the framework, as evidenced by the millions of calls to a number of methods down there and the 36 million IEnumerable.Contains() calls. Here is a snippet, this is all triggered by the first query done on the database (future queries don't do this and are fine).
What can I do to my model to make this less painful? Can I precompile this somehow? Better, can the EF team please address these issues or open source the framework so I can? Or at least fix the spelling of Warapper
? :)
EDIT: One specific EF call that triggers this is basically var db = new MyDbContext(); db.Personnel.Where(a => a.Login == login).SingleOrDefault();
. Also an EF Migrations Seed() AddOrUpdate generates effectively the same stack. The fuller stack trace, which may give a little more context, is here: Fuller Stack Trace
EDIT: Some relevant links:
EDIT2: Now that they just open sourced the code, it appears that this line:
//Filter the 1:1 foreign key associations to the ones relating the sets used in these cell wrappers.
oneToOneForeignKeyAssociationsForThisWrapper =
oneToOneForeignKeyAssociationsForThisWrapper.Where(
it => (it.AssociationEndMembers.All(endMember => entityTypes.Contains(endMember.GetEntityType()))));
is the one that needs some work. It's using an O(n^2) algorithm when it probably doesn't have to, but I haven't looked closely yet.
EDIT3: Happily, it looks like work in EF6 is fixing this code: http://entityframework.codeplex.com/discussions/396130
question from:
https://stackoverflow.com/questions/10757019/entity-framework-initialization-is-slow-what-can-i-do-to-bootstrap-it-faster 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…