Self Tracking Entities with Pre-Generated Views
I am currently using the Self Tracking entities of the .NET Entity Framework, ho开发者_运维问答wever I would like to speed up my execution of queries.
The first thing everyone seems to suggest is generate the views for the model at compile time.
Using the ssdl files etc, I was able to create a 'MyModel.Views.cs', which is compiled in my project. However I saw no benefit of this this what so ever? Am I missing something here? Do I get no benefit from this if I am using Self Tracking entities?
What other ways can I increase performance with the Entity Framework? How can I create Pre Compiled views, but supply with with parameters? A search query for example needs to take various different parameters, but could do with being made quicker!
Thanks
Well, remember that pre-generated views only help for certain operations. They help for queries which are built by the Entity Framework itself. For example, if you do a Load
on a related property, a pre-generated view will be used if it's available. If, on the other hand, you are doing projection or a custom Where
call, the pre-generated views cannot be used, since they do not represent your custom query. So it depends upon what you're doing.
The advantage of view pre-generation is that it's close to free. A little fiddling with your project file, and you get a performance boost on certain operations. But it doesn't make everything faster.
Pre-generated views are always used regardless of the query you are using. Let me explain what is pre-generated views. When you first query an entity data model, it is converted to esql views. This is first step which occurs at runtime and on demand when you query the model. Once that view is created, it is cached for the lifetime of application domain. However generating the view is only a one time cost just like as asp.net site which takes a first hit when someone accesses your site for the first time. You do save time for the first user but after that it is really the same experience. You should consider pre-generating views only if your model is big and have high startup cost for the first query. There are lot of ways to improve performance of self tracking entity and EF in general. I have a whole chapter in my book that talks about improving performance in EF.
精彩评论