简体   繁体   English

具有预生成视图的自我跟踪实体

[英]Self Tracking Entities with Pre-Generated Views

I am currently using the Self Tracking entities of the .NET Entity Framework, however I would like to speed up my execution of queries. 我目前正在使用.NET实体框架的自我跟踪实体,但是我想加快查询的执行速度。

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. 使用ssdl文件等,我能够创建一个“ MyModel.Views.cs”,该文件在我的项目中进行了编译。 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. 例如,如果对相关属性进行Load ,则将使用预先生成的视图(如果可用)。 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. 另一方面,如果您在进行投影或自定义的Where调用,则无法使用预生成的视图,因为它们不代表您的自定义查询。 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. 首次查询实体数据模型时,它会转换为esql视图。 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. 但是,生成视图仅是一次成本,就像asp.net网站在有人第一次访问您的网站时会受到第一点击一样。 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. 总的来说,有很多方法可以提高自我跟踪实体和EF的性能。 I have a whole chapter in my book that talks about improving performance in EF. 我的书中有一整章都谈到提高EF的性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM