【发布时间】:2016-08-10 06:09:48
【问题描述】:
如果我可以访问一个名为 procResults 的存储过程,它只返回一行数据,那么选择几个单个元素而不是整行是否会导致对数据库的多个查询?例如,如果我有:
Dim MyEntity As WhateverEntities = New WhateverEntities
Dim ResultName as String = MyEntity.procResults.Single().FullName
Dim ResultEmail as String = MyEntity.procResults.Single().Email
这是否会导致对数据库的两个实际查询,或者初始查询是否将整行存储在内存中并只为我提供我要求的两列?理想情况下,我只想返回这两列而不是整行,但不知道最有效的方法是什么。
【问题讨论】:
-
恕我直言,EF缓存结果的唯一部分是您使用Find时。
Note that DbSet [...] always create queries against the database and will always involve a round trip to the database even if the entities returned already exist in the context。查找:The Find method [...] uses the primary key value to attempt to find an entity tracked by the context. If the entity is not found in the context then a query will be sent to the database to find the entity there.
标签: sql-server vb.net entity-framework stored-procedures