EF FirstOfDefault查询的不是第一条记录问题
这是代码 WxUser是外键
这是数据 这三条数据的WxUser除了第二个都是同一个
为什么查出的是最后一条
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
这是代码 WxUser是外键
这是数据 这三条数据的WxUser除了第二个都是同一个
为什么查出的是最后一条
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
你可以用.orderby(x=>x.ID)排序一下试试看呢
SELECT
[Limit1].[ID] AS [ID],
[Limit1].[Name] AS [Name],
[Limit1].[Sex] AS [Sex],
[Limit1].[Phone] AS [Phone],
[Limit1].[Age] AS [Age],
[Limit1].[Category] AS [Category],
[Limit1].[Email] AS [Email],
[Limit1].[HostOrganization] AS [HostOrganization],
[Limit1].[Province] AS [Province],
[Limit1].[City] AS [City],
[Limit1].[Area] AS [Area],
[Limit1].[Address] AS [Address],
[Limit1].[Ip] AS [Ip],
[Limit1].[Country] AS [Country],
[Limit1].[Account] AS [Account],
[Limit1].[Password] AS [Password],
[Limit1].[CreateTime] AS [CreateTime],
[Limit1].[RegisterInfoId] AS [RegisterInfoId],
[Limit1].[HeadUrl] AS [HeadUrl],
[Limit1].[PassTime] AS [PassTime],
[Limit1].[Status] AS [Status],
[Limit1].[Message] AS [Message],
[Limit1].[Parent_ID] AS [Parent_ID],
[Limit1].[PdaUser_ID] AS [PdaUser_ID],
[Limit1].[WxUser_ID] AS [WxUser_ID],
[Limit1].[YzUser_ID] AS [YzUser_ID]
FROM ( SELECT TOP (1)
[Extent1].[ID] AS [ID],
[Extent1].[Name] AS [Name],
[Extent1].[Sex] AS [Sex],
[Extent1].[Phone] AS [Phone],
[Extent1].[Age] AS [Age],
[Extent1].[Category] AS [Category],
[Extent1].[Email] AS [Email],
[Extent1].[HostOrganization] AS [HostOrganization],
[Extent1].[Province] AS [Province],
[Extent1].[City] AS [City],
[Extent1].[Area] AS [Area],
[Extent1].[Address] AS [Address],
[Extent1].[Ip] AS [Ip],
[Extent1].[Country] AS [Country],
[Extent1].[Account] AS [Account],
[Extent1].[Password] AS [Password],
[Extent1].[CreateTime] AS [CreateTime],
[Extent1].[RegisterInfoId] AS [RegisterInfoId],
[Extent1].[HeadUrl] AS [HeadUrl],
[Extent1].[PassTime] AS [PassTime],
[Extent1].[Status] AS [Status],
[Extent1].[Message] AS [Message],
[Extent1].[Parent_ID] AS [Parent_ID],
[Extent1].[PdaUser_ID] AS [PdaUser_ID],
[Extent1].[WxUser_ID] AS [WxUser_ID],
[Extent1].[YzUser_ID] AS [YzUser_ID]
FROM [dbo].[YzMembers] AS [Extent1]
LEFT OUTER JOIN [dbo].[WxUsers] AS [Extent2] ON [Extent1].[WxUser_ID] = [Extent2].[ID]
WHERE ([Extent2].[OpenId] = @p__linq__0) OR (([Extent2].[OpenId] IS NULL) AND (@p__linq__0 IS NULL))
) AS [Limit1]
这是EF生成的SQL 如果直接在数据库中执行反而是和我想要的结果是一致的