Entity Framework 4.0 with Sql Compact Edition 4.0 performance issue
I have a web application with a EF model which I originally designed using a SQL Server 2008 backend. La开发者_开发问答ter on, I decided to use SQL CE for portability, so I converted the model to target Sql CE 4.0. However, I am running into serious performance issues when running this app.
For example, I have a portion in code that retrieves an entity from the database:
Trace.Write("Retrieving node from database", "Application");
var name = value.ToString();
var node = DataContext.Entities.Nodes
.SingleOrDefault(n => n.Name == name);
Trace.Write("Node retrieved from database ", "Application");
When I look at the trace information (trace.axd), those lines of code take a wooping 0.6 seconds!!
Trace Information
Category Message From First(s) From Last(s)
Application Retrieving node from database 0.00057591118424269 0.000576
Application Node retrieved from database 0.595122564460008 0.594547
And this happens everywhere in my application where I query by Name.
Any ideas? I'm guessing I have to define an index on the column, but how would I do that in the EF model?
EDIT : Gramma EDIT 2: Spelling in Title
I have a sample with some performance advice here, using global.asax: http://erikej.blogspot.com/2011/01/entity-framework-with-sql-server.html and other performance tips here: http://blogs.msdn.com/b/wriju/archive/2011/03/15/ado-net-entity-framework-performance-tips.aspx
I've used the older versions of SQL CE in the past, and I've found that one major bottleneck is opening the connection.
You might try managing the open connection on your own, and passing it into the data context by hand (rather than allowing the context to automatically manage the connection.)
精彩评论