我为我的项目使用 EF 5,并使用 EntityProfiler 对其进行分析,我看到当我使用 Find 进行查询时生成的 sql 是:
SELECT TOP (2) [Extent1].[ID] AS [ID],
[Extent1].[TargetID] AS [TargetID],
[Extent1].[BranchID] AS [BranchID],
[Extent1].[ApplicationStatus] AS [ApplicationStatus],
[Extent1].[UserID] AS [UserID],
[Extent1].[AssignedOfficer] AS [AssignedOfficer],
[Extent1].[AssignedOfficerCRM] AS [AssignedOfficerCRM],
[Extent1].[RegistrationDate] AS [RegistrationDate],
[Extent1].[DecisionReasons] AS [DecisionReasons],
[Extent1].[DecisionExceptionID] AS [DecisionExceptionID],
[Extent1].[RiskComment] AS [RiskComment],
[Extent1].[CESInformed] AS [CESInformed],
[Extent1].[IsCommited] AS [IsCommited]
FROM [dbo].[Applications] AS [Extent1]
WHERE [Extent1].[ID] = '900100' /* @p0 */
被调用的代码是:
public T GetByID(object primaryKey)
{
return DB.Set<T>().Find(primaryKey);
}
所以我的问题是为什么在生成的 sql 中是 Select Top (2)