我有这个Linq表达式(FirstOrDefault),它非常慢。Options是一个DbSet
DbOption dbo = ctx.Options.FirstOrDefault(o =>
o.SynN == oLoaded.SynN &&
o.OwnerId == oLoaded.OwnerId &&
o.Context == oLoaded.Context);
有一种方法可以更快地找到我的选项吗?我看到"表达式",但是我如何在表达式中转换这个Linq代码?我从来没用过。
感谢您的支持
如果记录太多,可以创建索引来提高对数据库的查询性能
CREATE NONCLUSTERED INDEX [IX_Options_SynN_OwnerId_Context] ON [dbo].[Options]
(
[SynN] ASC,
[OwnerId] ASC,
[Context] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO