I have a fairly large EF4 model, using POCO code gen. I’ve got lots of instances where I select a single entity from whichever table by its ID.
However on some tables, this takes 2 minutes or more, where on most tables it takes less than a second. I’m out of ideas as to where to look now, because I can’t see any reason. It’s always the same tables that cause problems, but I can query them directly against the database without problems, so it must be somewhere in Entity Framework territory that the problem is coming from.
The line is the quite innoccuous:
Dim newProd As New Product
Product.ShippingSize = Entities.ShippingSizes.Single(Function(ss) ss.Id = id)
- id is simply an integer passed in from the UI, Id on my entity is the primary key, which is indexed on the database
- Entities is a freshly created instance of my entity framework datacontext
- This is not the first query being executed against the Context, it is the first query against this EntitySet though
- I have re-indexed all tables having seen posts suggesting that a corrupt index could cause slow access, that hasn’t made any difference
- The exact same line of code against other tables runs almost instantly, it’s only certain tables
- This particular table is tiny – it only has 4 things in it
Any suggestions as to where to even start?
–edit – I’d oversimplified the code in the question to the point where the problem disappeared!
Where to start?
That should tell you whether you have a database problem or an EF problem.