{"id":442993,"date":"2024-12-26T03:54:03","date_gmt":"2024-12-26T03:54:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=442993"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-12-26T03:54:03","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=442993","title":{"rendered":"<span>\u041c\u0435\u0442\u043e\u0434 Contains \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u0432 Entity Framework \u0434\u043b\u044f SQL Server<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/5ac\/0b7\/281\/5ac0b728121e8eae397bff9ecb1f13d5.jpg\" alt=\"Contains \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u0432 Entity Framework \u0434\u043b\u044f SQL Server\" title=\"Contains \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u0432 Entity Framework \u0434\u043b\u044f SQL Server\" width=\"1172\" height=\"648\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5ac\/0b7\/281\/5ac0b728121e8eae397bff9ecb1f13d5.jpg\" data-blurred=\"true\"\/><\/p>\n<div><figcaption>Contains \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u0432 Entity Framework \u0434\u043b\u044f SQL Server<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0432 \u043c\u0435\u0442\u043e\u0434\u00a0<code>Contains()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 Entity Framework \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043d\u0435 \u0432\u043d\u043e\u0441\u0438\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f. \u0414\u043e \u0432\u044b\u0445\u043e\u0434\u0430 Entity Framework 8 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0441 \u044d\u0442\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 <code>where LINQ<\/code> \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0432\u0438\u0434\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>IN<\/code> \u0434\u043b\u044f SQL. \u0415\u0441\u043b\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0440\u0430\u0432\u043d\u043e \u043e\u0434\u043d\u043e\u043c\u0443, \u0442\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b\u043e \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c <code>\u2018=\u2019<\/code> \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 MS SQL Server. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438 \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f <code>Where() LINQ<\/code>.<\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 EF8 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>OPENJSON<\/code> \u0443\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u0442 \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u043a\u044d\u0448\u0435\u043c \u043f\u043b\u0430\u043d\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0434\u043b\u044f SQL Server, \u043d\u043e \u043d\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e \u043a \u0441\u0442\u0430\u0440\u044b\u043c \u0432\u0435\u0440\u0441\u0438\u044f\u043c (compatibility level) \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445. \u0414\u0430 \u0438 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u0435\u044e \u043a\u043e\u0434\u0430 \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u043c\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0412 \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u0432\u044b\u0448\u0435\u0434\u0448\u0435\u043c Entity Framework 9 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0434\u043b\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430\u00a0<code>Contains()<\/code> \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u043a\u0430\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e OPENJSON, \u0442\u0430\u043a \u0438 \u00ab\u043f\u043e-\u0441\u0442\u0430\u0440\u043e\u043c\u0443\u00bb \u2014 \u0432 \u0432\u0438\u0434\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442. \u041c\u043e\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0440\u0435\u0436\u0438\u043c \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u0439 \u0441\u043e \u0441\u0442\u0430\u0440\u044b\u043c\u0438 \u0432\u0435\u0440\u0441\u0438\u044f\u043c\u0438 SQL Server, \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 EF7.<\/p>\n<h2>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 EF7 \u0438 \u0440\u0430\u043d\u0435\u0435 <\/h2>\n<p>\u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439:  <\/p>\n<pre><code class=\"cs\">var ids = new[] { 1, 2, 3, 4, }; var employees = await dbcontext.Set&lt;Employee&gt;()     .Where(e =&gt; ids.Contains(e.Id));     .ToListAsync();<\/code><\/pre>\n<pre><code class=\"sql\">SELECT [e].[Id], [e].[BirthDate], [e].[DepartmentId], [e].[IsActive], [e].[Name] FROM [Employees] AS [e] WHERE [e].[Id] IN (1, 2, 3, 4)<\/code><\/pre>\n<p>\u041e\u0434\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"cs\">var ids = new[] { 1, }; var employees = await dbcontext.Set&lt;Employee&gt;()     .Where(e =&gt; ids.Contains(e.Id));     .ToListAsync();<\/code><\/pre>\n<pre><code class=\"sql\">SELECT [e].[Id], [e].[BirthDate], [e].[DepartmentId], [e].[IsActive], [e].[Name] FROM [Employees] AS [e] WHERE [e].[Id] = 1<\/code><\/pre>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 <code>LINQ<\/code> \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0438 \u0438\u043d\u043b\u0430\u0439\u043d \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 SQL.<\/p>\n<pre><code class=\"cs\">var query =      from e in dbcontext.Set&lt;Employee&gt;()     where new[] { 1, 2, 3, 4, }.Contains(e.Id)     select e; var employees = await query.ToListAsync();<\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u0435\u0449\u0451 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445. \u0422\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f <code>GroupBy()<\/code> \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 <code>Where()<\/code> \u043c\u043e\u0436\u0435\u0442 \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 <code>GROUP BY<\/code> \u0438 <code>HAVING<\/code> \u0434\u043b\u044f SQL.<\/p>\n<pre><code class=\"cs\">var departmentsIds = new[] { 1, 3, }; var query = dbcontext.Set&lt;Employee&gt;()     .GroupBy(g =&gt; g.DepartmentId)     .Select(e =&gt; new { Id = e.Key, Count = e.Count() })                     .Where(x =&gt; departmentsIds.Contains(x.Id))     .Select(e =&gt; new { e.Id, e.Count }); var employeesInDepartments = await query.ToListAsync();<\/code><\/pre>\n<pre><code class=\"sql\">SELECT [e].[DepartmentId] AS [Id], COUNT(*) AS [Count] FROM [Employees] AS [e] GROUP BY [e].[DepartmentId] HAVING [e].[DepartmentId] IN (1, 3)<\/code><\/pre>\n<h2>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 EF8 \u0438 EF9<\/h2>\n<p>\u0427\u0440\u0435\u0437\u043c\u0435\u0440\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0430\u0433\u0443\u0431\u043d\u043e\u0435 \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u043d\u0430 MS SQL Server. \u0425\u044d\u0448 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. SQL-\u0441\u0435\u0440\u0432\u0435\u0440\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430, \u0447\u0442\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f. \u0421\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u043c \u043f\u043b\u0430\u043d\u0430\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043e\u0442\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u043a\u044d\u0448\u0435 \u043f\u043b\u0430\u043d\u043e\u0432 SQL Server, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0432\u044b\u0442\u0435\u0441\u043d\u0435\u043d\u0438\u0435 \u0434\u0440\u0443\u0433\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0411\u043e\u0440\u044c\u0431\u0430 \u0437\u0430 \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u0443\u0433\u0440\u043e\u0436\u0430\u0435\u0442 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u044b\u043c\u0438 \u043f\u0435\u0440\u0435\u0441\u0447\u0451\u0442\u0430\u043c\u0438 \u043f\u043b\u0430\u043d\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. <\/p>\n<blockquote>\n<p>Entity Framework \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0439 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u043a\u044d\u0448 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442 \u0432 SQL \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u043c \u0440\u0430\u0441\u0445\u043e\u0434\u0430\u043c \u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435\u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u043c.  <\/p>\n<\/blockquote>\n<p>\u0412 Entity Framework 8 \u0441\u0442\u0430\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e SQL Server <code>OPENJSON<\/code> \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043f\u0438\u0441\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 JSON. \u042d\u0442\u043e\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u043a\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 SQL (<code>nvarchar(4000)<\/code> \u0438\u043b\u0438 <code>nvarchar(max)<\/code>). \u0422\u0430\u043a \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f SQL. <\/p>\n<p>\u041d\u043e \u0441\u0430\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c \u0441\u0442\u0430\u0440\u043e\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a <code>IN<\/code>. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>OPENJSON<\/code> \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0432 SQL Server 2014 \u0438 \u043d\u0438\u0436\u0435.  <\/p>\n<pre><code class=\"sql\">exec sp_executesql N'SELECT [e].[Id], [e].[BirthDate], [e].[DepartmentId], [e].[IsActive], [e].[Name] FROM [Employees] AS [e] WHERE [e].[Id] IN (     SELECT [i].[value]     FROM OPENJSON(@__ids_0) WITH ([value] int ''$'') AS [i] )',N'@__ids_0 nvarchar(4000)',@__ids_0=N'[1,2,3,4]'<\/code><\/pre>\n<h2>EF8 \u0434\u043b\u044f SQL Server 2014 \u0438 \u043d\u0438\u0436\u0435<\/h2>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>OPENJSON<\/code> \u0431\u044b\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 SQL Server 2016. \u0414\u043b\u044f \u0435\u0451 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043d\u0435 \u043d\u0438\u0436\u0435 130. \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<pre><code class=\"sql\">SELECT name, compatibility_level FROM sys.databases; <\/code><\/pre>\n<p>\u0412\u044b\u0437\u043e\u0432 <code>OPENJSON<\/code> \u0434\u043b\u044f SQL Server 2014 \u0438 \u043d\u0438\u0436\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441 \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 120 \u0438 \u043d\u0438\u0436\u0435, \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u0442\u0430\u043a\u043e\u0433\u043e \u0432\u0438\u0434\u0430:<\/p>\n<pre><code class=\"bash\">Msg 102, Level 15, State 1, Line 5 Incorrect syntax near '$'.<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c EF \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 SQL, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438.<\/p>\n<pre><code class=\"cs\">protected override void OnConfiguring(     DbContextOptionsBuilder optionsBuilder)         =&gt; optionsBuilder         .UseSqlServer(@\"&lt;CONNECTION STRING&gt;\", o =&gt; o.UseCompatibilityLevel(120));<\/code><\/pre>\n<h2>Where() \u0438 Contains() \u0438 EF9 <\/h2>\n<p>\u0412 Entity Framework 9 \u0442\u0430\u043a\u0436\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441\u043e \u0441\u0442\u0430\u0440\u044b\u043c\u0438 \u0432\u0435\u0440\u0441\u0438\u044f\u043c\u0438 SQL Server \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>UseCompatibilityLevel()<\/code>. \u0415\u0449\u0451 \u0432 EF9 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 <code>TranslateParameterizedCollectionsToConstants()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442 \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u00a0<code>Contains()<\/code>\u00a0\u0434\u043b\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u0432 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u0432\u043d\u0443\u0442\u0440\u0438 <code>IN<\/code> \u00ab\u043f\u043e \u0441\u0442\u0430\u0440\u043e\u043c\u0443\u00bb:<\/p>\n<pre><code class=\"cs\">protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)     =&gt; optionsBuilder.UseSqlServer(         \"&lt;CONNECTION STRING&gt;\",         o =&gt; o.TranslateParameterizedCollectionsToConstants());<\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c EF \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u0443\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0432 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b, \u043e\u0431\u0435\u0440\u043d\u0443\u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0432 <code>Constant&lt;T&gt;(T)<\/code>. \u042d\u0442\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e:<\/p>\n<pre><code class=\"cs\">var ids = new[] { 1, 2, 3, 4, }; var employees = await dbcontext.Set&lt;Employee&gt;()     .Where(e =&gt; EF.Constant(ids).Contains(e.Id))     .ToListAsync();<\/code><\/pre>\n<pre><code class=\"sql\">SELECT [e].[Id], [e].[BirthDate], [e].[DepartmentId], [e].[IsActive], [e].[Name] FROM [Employees] AS [e] WHERE [e].[Id] IN (1, 2, 3, 4)<\/code><\/pre>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0432 \u043e\u0434\u0438\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u043e\u0431\u0435\u0440\u043d\u0443\u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0432 <code>Parameter&lt;T&gt;(T)<\/code>. \u042d\u0442\u043e \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442 \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 <code>TranslateParameterizedCollectionsToConstants()<\/code>:  <\/p>\n<pre><code class=\"cs\">var ids = new[] { 1, 2, 3, 4, }; var employees = await dbcontext.Set&lt;Employee&gt;()     .Where(e =&gt; EF.Parameter(ids).Contains(e.Id))     .ToListAsync();<\/code><\/pre>\n<pre><code class=\"sql\">exec sp_executesql N'SELECT [e].[Id], [e].[BirthDate], [e].[DepartmentId], [e].[IsActive], [e].[Name] FROM [Employees] AS [e] WHERE [e].[Id] IN (     SELECT [i].[value]     FROM OPENJSON(@__ids_0) WITH ([value] int ''$'') AS [i] )',N'@__ids_0 nvarchar(4000)',@__ids_0=N'[1,2,3,4]'<\/code><\/pre>\n<h2>\u041f\u043b\u0430\u043d\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/h2>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>OPENJSON<\/code> \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441\u0430 \u0441 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u043b\u0430\u043d\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 SQL. \u042d\u0442\u043e \u0432\u0430\u0436\u043d\u043e \u0434\u043b\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u0436\u0435 \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438. <\/p>\n<p>\u041d\u043e \u0432\u043e\u0442 \u0441\u0430\u043c\u0438 \u043f\u043b\u0430\u043d\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c\u0438. \u0412 EF8 \u0438 EF9 \u0434\u0430\u0436\u0435 \u043e\u0434\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442\u0441\u044f \u0432 SQL \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>OPENJSON<\/code>.<\/p>\n<pre><code class=\"cs\">var ids = new[] { 1, }; var employees = await dbcontext.Set&lt;Employee&gt;()     .Where(e =&gt; ids.Contains(e.Id));     .ToListAsync();<\/code><\/pre>\n<pre><code class=\"sql\">exec sp_executesql N'SELECT [e].[Id], [e].[BirthDate], [e].[DepartmentId], [e].[IsActive], [e].[Name] FROM [Employees] AS [e] WHERE [e].[Id] IN (     SELECT [i].[value]     FROM OPENJSON(@__ids_0) WITH ([value] int ''$'') AS [i] )',N'@__ids_0 nvarchar(4000)',@__ids_0=N'[1]'<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/f31\/23e\/8de\/f3123e8de5de8ffcebe23ddd29495e06.jpg\" alt=\"\u041f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f OPENJSON\" title=\"\u041f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f OPENJSON\" width=\"1082\" height=\"539\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f31\/23e\/8de\/f3123e8de5de8ffcebe23ddd29495e06.jpg\" data-blurred=\"true\"\/><\/p>\n<div><figcaption>\u041f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f OPENJSON<\/figcaption><\/div>\n<\/figure>\n<p>\u0415\u0441\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0443\u0439\u0442\u0438 \u0432 <code>INDEX SCAN<\/code> \u0442\u0430\u043c, \u0433\u0434\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0431\u0435\u0437 <code>OPENJSON<\/code> \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a <code>INDEX SEEK<\/code>.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/4fb\/530\/47a\/4fb53047a66652de2f7742fb23438cdf.jpg\" alt=\"\u041f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f EF7\" title=\"\u041f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f EF7\" width=\"1082\" height=\"336\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4fb\/530\/47a\/4fb53047a66652de2f7742fb23438cdf.jpg\" data-blurred=\"true\"\/><\/p>\n<div><figcaption>\u041f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f EF7<\/figcaption><\/div>\n<\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e52\/31a\/5c3\/e5231a5c3533ca1a134f728432b89031.png\" alt=\"\u041f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\" title=\"\u041f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\" width=\"1157\" height=\"325\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e52\/31a\/5c3\/e5231a5c3533ca1a134f728432b89031.png\"\/><\/p>\n<div><figcaption>\u041f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430<\/figcaption><\/div>\n<\/figure>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>INDEX SCAN<\/code> \u0434\u043b\u044f  <code>OPENJSON<\/code> \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u043c\u043e\u0436\u0435\u0442 \u043e\u043f\u0440\u0430\u0432\u0434\u0430\u0442\u044c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u0415\u0441\u043b\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441\u0442\u0440\u043e\u043a, \u0442\u043e \u043f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u043e\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c <code>Id<\/code>.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/957\/7ca\/7e1\/9577ca7e1173e6b86a059b200fc6449b.png\" alt=\"\u041f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f OPENJSON \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b\" title=\"\u041f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f OPENJSON \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b\" width=\"1159\" height=\"540\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/957\/7ca\/7e1\/9577ca7e1173e6b86a059b200fc6449b.png\"\/><\/p>\n<div><figcaption>\u041f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f OPENJSON \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/figcaption><\/div>\n<\/figure>\n<h2>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Contain() \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u044f OR<\/h2>\n<p>\u0414\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043d\u0435 \u043f\u043e\u0442\u0435\u0440\u044f\u043b\u0438 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u044e\u0442 <code>Contains()<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 <code>Where()<\/code> \u0432 \u043d\u0430\u0431\u043e\u0440 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 <code>OR<\/code> \u0434\u043b\u044f SQL. \u0423\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0430\u043a\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043b\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0438\u0437 \u0442\u0440\u0451\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"sql\">exec sp_executesql N'SELECT * FROM Employees WHERE Id = @v1 OR Id = @v2 OR Id = @v3', N'@v1 int,@v2 int,@v3 int', @v1=1,@v2=2,@v3=3<\/code><\/pre>\n<p>\u0415\u0441\u0442\u044c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0435 \u043d\u0430 \u0432\u0445\u043e\u0434 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e, \u0430 \u0434\u043b\u044f \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043b\u0443\u0447\u0448\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c <code>HashSet<\/code>.<\/p>\n<pre><code class=\"cs\">  var ids = new[] { 1, 2, 3, 4, 5, 6, 7, };   var employees = await dbcontext.Set&lt;Employee&gt;().In(       [.. ids], x =&gt; x.Id).ToListAsync();<\/code><\/pre>\n<pre><code class=\"sql\">exec sp_executesql N'SELECT [e].[Id], [e].[BirthDate], [e].[DepartmentId], [e].[IsActive], [e].[Name] FROM [Employees] AS [e] WHERE [e].[Id] = @__v1_0 OR [e].[Id] = @__v2_1 OR [e].[Id] = @__v1_2 OR [e].[Id] = @__v1_3 OR [e].[Id] = @__v2_4 OR [e].[Id] = @__v1_5 OR [e].[Id] = @__v2_6 OR [e].[Id] = @__v1_7 OR [e].[Id] = @__v1_8 OR [e].[Id] = @__v2_9',N'@__v1_0 int,@__v2_1 int,@__v1_2 int,@__v1_3 int,@__v2_4 int,@__v1_5 int,@__v2_6 int,@__v1_7 int,@__v1_8 int,@__v2_9 int', @__v1_0=1,@__v2_1=2,@__v1_2=3,@__v1_3=4,@__v2_4=5,@__v1_5=6,@__v2_6=7,@__v1_7=7,@__v1_8=7,@__v2_9=7<\/code><\/pre>\n<p>\u0423 \u044d\u0442\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0435\u0441\u0442\u044c \u0445\u043e\u0440\u043e\u0448\u0438\u0435 \u0448\u0430\u043d\u0441\u044b \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u043a\u043e\u0440\u0437\u0438\u043d (\u0431\u0430\u043a\u0435\u0442\u043e\u0432) \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 SQL Server \u043e\u0442 \u0437\u0430\u0445\u043b\u0430\u043c\u043b\u0435\u043d\u0438\u044f \u043f\u043b\u0430\u043d\u0430\u043c\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<p>\u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e\u043f\u0430\u043b\u043e \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043c\u0435\u0440\u0430\u043c\u0438 \u043a\u043e\u0440\u0437\u0438\u043d 6 \u0438 10. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e <code>Id<\/code> \u0431\u044b\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0435\u0449\u0451 \u0442\u0440\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u043f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f \u0441\u0435\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0412\u0441\u0435\u0433\u043e \u0434\u043b\u044f <code>7<\/code> \u0438\u0445 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0447\u0435\u0442\u044b\u0440\u0435:<\/p>\n<pre><code>@__v2_6=7,@__v1_7=7,@__v1_8=7,@__v2_9=7<\/code><\/pre>\n<p>\u0415\u0441\u0442\u044c \u0443 \u0442\u0430\u043a\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043c\u0438\u043d\u0443\u0441\u044b. \u0422\u0435\u043a\u0441\u0442 SQL \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f \u043a\u0440\u0443\u043f\u043d\u044b\u0445 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u0441 <code>OPENJSON<\/code> \u0438\u043b\u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c <code>IN<\/code>. \u0412 MS SQL \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432 \u043e\u0434\u043d\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u2014 \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 2100. \u041d\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438, \u0432\u044b\u043a\u0430\u0447\u0438\u0432\u0430\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438.<\/p>\n<pre><code class=\"cs\">var ids = new[] { 1, 2, 3, 4, 5, 6, 7, }; var employees = await dbcontext.Set&lt;Employee&gt;().ToListByPortionsAsync(     [.. ids], x =&gt; x.Id, portionSize: 4);<\/code><\/pre>\n<pre><code class=\"sql\">exec sp_executesql N'SELECT [e].[Id], [e].[BirthDate], [e].[DepartmentId], [e].[IsActive], [e].[Name] FROM [Employees] AS [e] WHERE [e].[Id] = @__v1_0 OR [e].[Id] = @__v2_1 OR [e].[Id] = @__v1_2 OR [e].[Id] = @__v2_3',N'@__v1_0 int,@__v2_1 int,@__v1_2 int,@__v2_3 int',@__v1_0=1,@__v2_1=2,@__v1_2=3,@__v2_3=4 go exec sp_executesql N'SELECT [e].[Id], [e].[BirthDate], [e].[DepartmentId], [e].[IsActive], [e].[Name] FROM [Employees] AS [e] WHERE [e].[Id] = @__v1_0 OR [e].[Id] = @__v2_1 OR [e].[Id] = @__v1_2',N'@__v1_0 int,@__v2_1 int,@__v1_2 int',@__v1_0=5,@__v2_1=6,@__v1_2=7 go<\/code><\/pre>\n<p>\u0420\u0430\u0437\u043c\u0435\u0440\u044b \u043a\u043e\u0440\u0437\u0438\u043d \u043b\u0443\u0447\u0448\u0435 \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0441\u0442\u0440\u043e\u043a \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0432 UI \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0438 \u0442\u0435\u0441\u0442\u044b \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438:<\/p>\n<div class=\"embed_link\">\n<div class=\"embed__thumb\" style=\"background-image: url(&quot;https:\/\/opengraph.githubassets.com\/dab15ca443e30520d97a77ed26d2ef6fb53a15f0b9d743d692a0a6512f3eb3a6\/aidecode\/qef&quot;);\"><\/div>\n<div class=\"embed__caption\">\n<div class=\"embed__caption-title\"><span>qef\/test at main \u00b7 aidecode\/qef<\/span><\/div>\n<p><a href=\"https:\/\/github.com\/aidecode\/qef\/tree\/main\/test\" target=\"_blank\" rel=\"noopener noreferrer nofollow\" class=\"embed__caption-host\">github.com<\/a><\/div>\n<\/div>\n<p>\u0421\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0441\u0442\u0430\u0442\u044c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u0434\u043b\u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430:<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/learn.microsoft.com\/ru-ru\/ef\/core\/what-is-new\/ef-core-8.0\/breaking-changes#sqlserver-contains-compatibility\">\u041a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 EF Core 8.0<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-ef8-preview-4\/\">EF Core 8 Preview 4: Primitive collections and improved Contains<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/github.com\/dotnet\/efcore\/issues\/32394\">Contains to OPENJSON translation regresses performance #32394<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/gist.github.com\/ErikEJ\/6ab62e8b9c226ecacf02a5e5713ff7bd\">IQueryableExtensions.cs<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/869120\/\"> https:\/\/habr.com\/ru\/articles\/869120\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\">\n<div><figcaption>Contains \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u0432 Entity Framework \u0434\u043b\u044f SQL Server<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0432 \u043c\u0435\u0442\u043e\u0434\u00a0<code>Contains()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 Entity Framework \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043d\u0435 \u0432\u043d\u043e\u0441\u0438\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f. \u0414\u043e \u0432\u044b\u0445\u043e\u0434\u0430 Entity Framework 8 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0441 \u044d\u0442\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 <code>where LINQ<\/code> \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0432\u0438\u0434\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>IN<\/code> \u0434\u043b\u044f SQL. \u0415\u0441\u043b\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0440\u0430\u0432\u043d\u043e \u043e\u0434\u043d\u043e\u043c\u0443, \u0442\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b\u043e \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c <code>\u2018=\u2019<\/code> \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 MS SQL Server. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438 \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f <code>Where() LINQ<\/code>.<\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 EF8 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>OPENJSON<\/code> \u0443\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u0442 \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u043a\u044d\u0448\u0435\u043c \u043f\u043b\u0430\u043d\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0434\u043b\u044f SQL Server, \u043d\u043e \u043d\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e \u043a \u0441\u0442\u0430\u0440\u044b\u043c \u0432\u0435\u0440\u0441\u0438\u044f\u043c (compatibility level) \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445. \u0414\u0430 \u0438 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u0435\u044e \u043a\u043e\u0434\u0430 \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u043c\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0412 \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u0432\u044b\u0448\u0435\u0434\u0448\u0435\u043c Entity Framework 9 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u0434\u043b\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430\u00a0<code>Contains()<\/code> \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u043a\u0430\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e OPENJSON, \u0442\u0430\u043a \u0438 \u00ab\u043f\u043e-\u0441\u0442\u0430\u0440\u043e\u043c\u0443\u00bb \u2014 \u0432 \u0432\u0438\u0434\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442. \u041c\u043e\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0440\u0435\u0436\u0438\u043c \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u0439 \u0441\u043e \u0441\u0442\u0430\u0440\u044b\u043c\u0438 \u0432\u0435\u0440\u0441\u0438\u044f\u043c\u0438 SQL Server, \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 EF7.<\/p>\n<h2>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 EF7 \u0438 \u0440\u0430\u043d\u0435\u0435 <\/h2>\n<p>\u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439:  <\/p>\n<pre><code class=\"cs\">var ids = new[] { 1, 2, 3, 4, }; var employees = await dbcontext.Set&lt;Employee&gt;()     .Where(e =&gt; ids.Contains(e.Id));     .ToListAsync();<\/code><\/pre>\n<pre><code class=\"sql\">SELECT [e].[Id], [e].[BirthDate], [e].[DepartmentId], [e].[IsActive], [e].[Name] FROM [Employees] AS [e] WHERE [e].[Id] IN (1, 2, 3, 4)<\/code><\/pre>\n<p>\u041e\u0434\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"cs\">var ids = new[] { 1, }; var employees = await dbcontext.Set&lt;Employee&gt;()     .Where(e =&gt; ids.Contains(e.Id));     .ToListAsync();<\/code><\/pre>\n<pre><code class=\"sql\">SELECT [e].[Id], [e].[BirthDate], [e].[DepartmentId], [e].[IsActive], [e].[Name] FROM [Employees] AS [e] WHERE [e].[Id] = 1<\/code><\/pre>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 <code>LINQ<\/code> \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0438 \u0438\u043d\u043b\u0430\u0439\u043d \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 SQL.<\/p>\n<pre><code class=\"cs\">var query =      from e in dbcontext.Set&lt;Employee&gt;()     where new[] { 1, 2, 3, 4, }.Contains(e.Id)     select e; var employees = await query.ToListAsync();<\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u0435\u0449\u0451 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445. \u0422\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f <code>GroupBy()<\/code> \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 <code>Where()<\/code> \u043c\u043e\u0436\u0435\u0442 \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 <code>GROUP BY<\/code> \u0438 <code>HAVING<\/code> \u0434\u043b\u044f SQL.<\/p>\n<pre><code class=\"cs\">var departmentsIds = new[] { 1, 3, }; var query = dbcontext.Set&lt;Employee&gt;()     .GroupBy(g =&gt; g.DepartmentId)     .Select(e =&gt; new { Id = e.Key, Count = e.Count() })                     .Where(x =&gt; departmentsIds.Contains(x.Id))     .Select(e =&gt; new { e.Id, e.Count }); var employeesInDepartments = await query.ToListAsync();<\/code><\/pre>\n<pre><code class=\"sql\">SELECT [e].[DepartmentId] AS [Id], COUNT(*) AS [Count] FROM [Employees] AS [e] GROUP BY [e].[DepartmentId] HAVING [e].[DepartmentId] IN (1, 3)<\/code><\/pre>\n<h2>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 EF8 \u0438 EF9<\/h2>\n<p>\u0427\u0440\u0435\u0437\u043c\u0435\u0440\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0430\u0433\u0443\u0431\u043d\u043e\u0435 \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u043d\u0430 MS SQL Server. \u0425\u044d\u0448 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. SQL-\u0441\u0435\u0440\u0432\u0435\u0440\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430, \u0447\u0442\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f. \u0421\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u043c \u043f\u043b\u0430\u043d\u0430\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043e\u0442\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u043a\u044d\u0448\u0435 \u043f\u043b\u0430\u043d\u043e\u0432 SQL Server, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0432\u044b\u0442\u0435\u0441\u043d\u0435\u043d\u0438\u0435 \u0434\u0440\u0443\u0433\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0411\u043e\u0440\u044c\u0431\u0430 \u0437\u0430 \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u0443\u0433\u0440\u043e\u0436\u0430\u0435\u0442 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u044b\u043c\u0438 \u043f\u0435\u0440\u0435\u0441\u0447\u0451\u0442\u0430\u043c\u0438 \u043f\u043b\u0430\u043d\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. <\/p>\n<blockquote>\n<p>Entity Framework \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0439 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u043a\u044d\u0448 \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442 \u0432 SQL \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u043c \u0440\u0430\u0441\u0445\u043e\u0434\u0430\u043c \u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435\u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u043c.  <\/p>\n<\/blockquote>\n<p>\u0412 Entity Framework 8 \u0441\u0442\u0430\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e SQL Server <code>OPENJSON<\/code> \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043f\u0438\u0441\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 JSON. \u042d\u0442\u043e\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u043a\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 SQL (<code>nvarchar(4000)<\/code> \u0438\u043b\u0438 <code>nvarchar(max)<\/code>). \u0422\u0430\u043a \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f SQL. <\/p>\n<p>\u041d\u043e \u0441\u0430\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0447\u0435\u043c \u0441\u0442\u0430\u0440\u043e\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a <code>IN<\/code>. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>OPENJSON<\/code> \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0432 SQL Server 2014 \u0438 \u043d\u0438\u0436\u0435.  <\/p>\n<pre><code class=\"sql\">exec sp_executesql N'SELECT [e].[Id], [e].[BirthDate], [e].[DepartmentId], [e].[IsActive], [e].[Name] FROM [Employees] AS [e] WHERE [e].[Id] IN (     SELECT [i].[value]     FROM OPENJSON(@__ids_0) WITH ([value] int ''$'') AS [i] )',N'@__ids_0 nvarchar(4000)',@__ids_0=N'[1,2,3,4]'<\/code><\/pre>\n<h2>EF8 \u0434\u043b\u044f SQL Server 2014 \u0438 \u043d\u0438\u0436\u0435<\/h2>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>OPENJSON<\/code> \u0431\u044b\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 SQL Server 2016. \u0414\u043b\u044f \u0435\u0451 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043d\u0435 \u043d\u0438\u0436\u0435 130. \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<pre><code class=\"sql\">SELECT name, compatibility_level FROM sys.databases; <\/code><\/pre>\n<p>\u0412\u044b\u0437\u043e\u0432 <code>OPENJSON<\/code> \u0434\u043b\u044f SQL Server 2014 \u0438 \u043d\u0438\u0436\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441 \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 120 \u0438 \u043d\u0438\u0436\u0435, \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u0442\u0430\u043a\u043e\u0433\u043e \u0432\u0438\u0434\u0430:<\/p>\n<pre><code class=\"bash\">Msg 102, Level 15, State 1, Line 5 Incorrect syntax near '$'.<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c EF \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 SQL, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438.<\/p>\n<pre><code class=\"cs\">protected override void OnConfiguring(     DbContextOptionsBuilder optionsBuilder)         =&gt; optionsBuilder         .UseSqlServer(@\"&lt;CONNECTION STRING&gt;\", o =&gt; o.UseCompatibilityLevel(120));<\/code><\/pre>\n<h2>Where() \u0438 Contains() \u0438 EF9 <\/h2>\n<p>\u0412 Entity Framework 9 \u0442\u0430\u043a\u0436\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441\u043e \u0441\u0442\u0430\u0440\u044b\u043c\u0438 \u0432\u0435\u0440\u0441\u0438\u044f\u043c\u0438 SQL Server \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>UseCompatibilityLevel()<\/code>. \u0415\u0449\u0451 \u0432 EF9 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 <code>TranslateParameterizedCollectionsToConstants()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442 \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u00a0<code>Contains()<\/code>\u00a0\u0434\u043b\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u0432 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u0432\u043d\u0443\u0442\u0440\u0438 <code>IN<\/code> \u00ab\u043f\u043e \u0441\u0442\u0430\u0440\u043e\u043c\u0443\u00bb:<\/p>\n<pre><code class=\"cs\">protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)     =&gt; optionsBuilder.UseSqlServer(         \"&lt;CONNECTION STRING&gt;\",         o =&gt; o.TranslateParameterizedCollectionsToConstants());<\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c EF \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u0443\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0432 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b, \u043e\u0431\u0435\u0440\u043d\u0443\u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0432 <code>Constant&lt;T&gt;(T)<\/code>. \u042d\u0442\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e:<\/p>\n<pre><code class=\"cs\">var ids = new[] { 1, 2, 3, 4, }; var employees = await dbcontext.Set&lt;Employee&gt;()     .Where(e =&gt; EF.Constant(ids).Contains(e.Id))     .ToListAsync();<\/code><\/pre>\n<pre><code class=\"sql\">SELECT [e].[Id], [e].[BirthDate], [e].[DepartmentId], [e].[IsActive], [e].[Name] FROM [Employees] AS [e] WHERE [e].[Id] IN (1, 2, 3, 4)<\/code><\/pre>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0432 \u043e\u0434\u0438\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u043e\u0431\u0435\u0440\u043d\u0443\u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0432 <code>Parameter&lt;T&gt;(T)<\/code>. \u042d\u0442\u043e \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442 \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 <code>TranslateParameterizedCollectionsToConstants()<\/code>:  <\/p>\n<pre><code class=\"cs\">var ids = new[] { 1, 2, 3, 4, }; var employees = await dbcontext.Set&lt;Employee&gt;()     .Where(e =&gt; EF.Parameter(ids).Contains(e.Id))     .ToListAsync();<\/code><\/pre>\n<pre><code class=\"sql\">exec sp_executesql N'SELECT [e].[Id], [e].[BirthDate], [e].[DepartmentId], [e].[IsActive], [e].[Name] FROM [Employees] AS [e] WHERE [e].[Id] IN (     SELECT [i].[value]     FROM OPENJSON(@__ids_0) WITH ([value] int ''$'') AS [i] )',N'@__ids_0 nvarchar(4000)',@__ids_0=N'[1,2,3,4]'<\/code><\/pre>\n<h2>\u041f\u043b\u0430\u043d\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/h2>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>OPENJSON<\/code> \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441\u0430 \u0441 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u043b\u0430\u043d\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 SQL. \u042d\u0442\u043e \u0432\u0430\u0436\u043d\u043e \u0434\u043b\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u0436\u0435 \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438. <\/p>\n<p>\u041d\u043e \u0432\u043e\u0442 \u0441\u0430\u043c\u0438 \u043f\u043b\u0430\u043d\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c\u0438. \u0412 EF8 \u0438 EF9 \u0434\u0430\u0436\u0435 \u043e\u0434\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442\u0441\u044f \u0432 SQL \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>OPENJSON<\/code>.<\/p>\n<pre><code class=\"cs\">var ids = new[] { 1, }; var employees = await dbcontext.Set&lt;Employee&gt;()     .Where(e =&gt; ids.Contains(e.Id));     .ToListAsync();<\/code><\/pre>\n<pre><code class=\"sql\">exec sp_executesql N'SELECT [e].[Id], [e].[BirthDate], [e].[DepartmentId], [e].[IsActive], [e].[Name] FROM [Employees] AS [e] WHERE [e].[Id] IN (     SELECT [i].[value]     FROM OPENJSON(@__ids_0) WITH ([value] int ''$'') AS [i] )',N'@__ids_0 nvarchar(4000)',@__ids_0=N'[1]'<\/code><\/pre>\n<figure class=\"full-width\">\n<div><figcaption>\u041f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f OPENJSON<\/figcaption><\/div>\n<\/figure>\n<p>\u0415\u0441\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0443\u0439\u0442\u0438 \u0432 <code>INDEX SCAN<\/code> \u0442\u0430\u043c, \u0433\u0434\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0431\u0435\u0437 <code>OPENJSON<\/code> \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a <code>INDEX SEEK<\/code>.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u041f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f EF7<\/figcaption><\/div>\n<\/figure>\n<figure class=\"full-width\">\n<div><figcaption>\u041f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430<\/figcaption><\/div>\n<\/figure>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>INDEX SCAN<\/code> \u0434\u043b\u044f  <code>OPENJSON<\/code> \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 \u043c\u043e\u0436\u0435\u0442 \u043e\u043f\u0440\u0430\u0432\u0434\u0430\u0442\u044c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u0415\u0441\u043b\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441\u0442\u0440\u043e\u043a, \u0442\u043e \u043f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u043e\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c <code>Id<\/code>.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u041f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f OPENJSON \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b<\/figcaption><\/div>\n<\/figure>\n<h2>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Contain() \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u044f OR<\/h2>\n<p>\u0414\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043d\u0435 \u043f\u043e\u0442\u0435\u0440\u044f\u043b\u0438 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u044e\u0442 <code>Contains()<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 <code>Where()<\/code> \u0432 \u043d\u0430\u0431\u043e\u0440 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 <code>OR<\/code> \u0434\u043b\u044f SQL. \u0423\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0442\u0430\u043a\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043b\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0438\u0437 \u0442\u0440\u0451\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"sql\">exec sp_executesql N'SELECT * FROM Employees WHERE Id = @v1 OR Id = @v2 OR Id = @v3', N'@v1 int,@v2 int,@v3 int', @v1=1,@v2=2,@v3=3<\/code><\/pre>\n<p>\u0415\u0441\u0442\u044c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0435 \u043d\u0430 \u0432\u0445\u043e\u0434 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e, \u0430 \u0434\u043b\u044f \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043b\u0443\u0447\u0448\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c <code>HashSet<\/code>.<\/p>\n<pre><code class=\"cs\">  var ids = new[] { 1, 2, 3, 4, 5, 6, 7, };   var employees = await dbcontext.Set&lt;Employee&gt;().In(       [.. ids], x =&gt; x.Id).ToListAsync();<\/code><\/pre>\n<pre><code class=\"sql\">exec sp_executesql N'SELECT [e].[Id], [e].[BirthDate], [e].[DepartmentId], [e].[IsActive], [e].[Name] FROM [Employees] AS [e] WHERE [e].[Id] = @__v1_0 OR [e].[Id] = @__v2_1 OR [e].[Id] = @__v1_2 OR [e].[Id] = @__v1_3 OR [e].[Id] = @__v2_4 OR [e].[Id] = @__v1_5 OR [e].[Id] = @__v2_6 OR [e].[Id] = @__v1_7 OR [e].[Id] = @__v1_8 OR [e].[Id] = @__v2_9',N'@__v1_0 int,@__v2_1 int,@__v1_2 int,@__v1_3 int,@__v2_4 int,@__v1_5 int,@__v2_6 int,@__v1_7 int,@__v1_8 int,@__v2_9 int', @__v1_0=1,@__v2_1=2,@__v1_2=3,@__v1_3=4,@__v2_4=5,@__v1_5=6,@__v2_6=7,@__v1_7=7,@__v1_8=7,@__v2_9=7<\/code><\/pre>\n<p>\u0423 \u044d\u0442\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0435\u0441\u0442\u044c \u0445\u043e\u0440\u043e\u0448\u0438\u0435 \u0448\u0430\u043d\u0441\u044b \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u043a\u043e\u0440\u0437\u0438\u043d (\u0431\u0430\u043a\u0435\u0442\u043e\u0432) \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 SQL Server \u043e\u0442 \u0437\u0430\u0445\u043b\u0430\u043c\u043b\u0435\u043d\u0438\u044f \u043f\u043b\u0430\u043d\u0430\u043c\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<p>\u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u043e\u043f\u0430\u043b\u043e \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043c\u0435\u0440\u0430\u043c\u0438 \u043a\u043e\u0440\u0437\u0438\u043d 6 \u0438 10. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e <code>Id<\/code> \u0431\u044b\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0435\u0449\u0451 \u0442\u0440\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u043f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f \u0441\u0435\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0412\u0441\u0435\u0433\u043e \u0434\u043b\u044f <code>7<\/code> \u0438\u0445 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0447\u0435\u0442\u044b\u0440\u0435:<\/p>\n<pre><code>@__v2_6=7,@__v1_7=7,@__v1_8=7,@__v2_9=7<\/code><\/pre>\n<p>\u0415\u0441\u0442\u044c \u0443 \u0442\u0430\u043a\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043c\u0438\u043d\u0443\u0441\u044b. \u0422\u0435\u043a\u0441\u0442 SQL \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043b\u044f \u043a\u0440\u0443\u043f\u043d\u044b\u0445 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u0441 <code>OPENJSON<\/code> \u0438\u043b\u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c <code>IN<\/code>. \u0412 MS SQL \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432 \u043e\u0434\u043d\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u2014 \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 2100. \u041d\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438, \u0432\u044b\u043a\u0430\u0447\u0438\u0432\u0430\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438.<\/p>\n<pre><code class=\"cs\">var ids = new[] { 1, 2, 3, 4, 5, 6, 7, }; var employees = await dbcontext.Set&lt;Employee&gt;().ToListByPortionsAsync(     [.. ids], x =&gt; x.Id, portionSize: 4);<\/code><\/pre>\n<pre><code class=\"sql\">exec sp_executesql N'SELECT [e].[Id], [e].[BirthDate], [e].[DepartmentId], [e].[IsActive], [e].[Name] FROM [Employees] AS [e] WHERE [e].[Id] = @__v1_0 OR [e].[Id] = @__v2_1 OR [e].[Id] = @__v1_2 OR [e].[Id] = @__v2_3',N'@__v1_0 int,@__v2_1 int,@__v1_2 int,@__v2_3 int',@__v1_0=1,@__v2_1=2,@__v1_2=3,@__v2_3=4 go exec sp_executesql N'SELECT [e].[Id], [e].[BirthDate],<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-442993","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/442993","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=442993"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/442993\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=442993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=442993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=442993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}