{"id":298478,"date":"2020-02-10T15:00:47","date_gmt":"2020-02-10T15:00:47","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=298478"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=298478","title":{"rendered":"\u0423\u0441\u043a\u043e\u0440\u044f\u0435\u043c\u0441\u044f \u0432 Entity Framework Core"},"content":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/487734\/\">\n<h4>\u041d\u0435 \u0431\u0443\u0434\u044c \u0436\u0430\u0434\u0438\u043d\u043e\u0439!<\/h4>\n<p>  \u041f\u0440\u0438 \u0432\u044b\u0431\u043e\u0440\u043a\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u043e \u0440\u043e\u0432\u043d\u043e \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e \u0437\u0430 \u043e\u0434\u0438\u043d \u0440\u0430\u0437. \u041d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0439\u0442\u0435 \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b!<\/p>\n<p>  <u>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/u><\/p>\n<pre><code class=\"cs\">using var ctx = new EFCoreTestContext(optionsBuilder.Options);                 \/\/ \u041c\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043a\u043e\u043b\u043e\u043d\u043a\u0443 ID \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u043d\u043e \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0438 \u044d\u0442\u043e \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e! ctx.FederalDistricts.Select(x=&gt; new { x.ID, x.Name, x.ShortName }).ToList(); <\/code><\/pre>\n<p>  <u>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/u><\/p>\n<pre><code class=\"cs\">using var ctx = new EFCoreTestContext(optionsBuilder.Options);   \/\/ \u041c\u044b \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043a\u043e\u043b\u043e\u043d\u043a\u0443 ID \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0438 \u044d\u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e! ctx.FederalDistricts.Select(x=&gt; new { x.Name, x.ShortName }).ToList(); ctx.FederalDistricts.Select(x =&gt; new MyClass { Name = x.Name, ShortName = x.ShortName }).ToList(); <\/code><\/pre>\n<p>  <a name=\"habracut\"><\/a><br \/>  <u>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/u><\/p>\n<pre><code class=\"cs\">var blogs = context.Blog.ToList(); \/\/ \u0422\u0443\u0442 \u0432\u044b \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0412\u0421\u042e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432 \u043f\u0430\u043c\u044f\u0442\u044c. \u0417\u0430\u0447\u0435\u043c? \/\/ \u0427\u0442\u043e\u0431\u044b \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043b\u0438\u0448\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u0438? var somePost = blogs.FirstOrDefault(x=&gt;x.Title.StartWidth(\u201cHello world!\u201d)); <\/code><\/pre>\n<p>  <u>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/u><\/p>\n<pre><code class=\"cs\">var somePost = context.Blog.FirstOrDefault(x=&gt;x.Title.StartWidth(\u201cHello world!\u201d)); <\/code><\/pre>\n<p>  \u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u0435\u0440\u043d\u0443\u043b \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u0438. <\/p>\n<p>  <u>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/u><\/p>\n<pre><code class=\"cs\"> var blogs = context.Blogs.Where(blog =&gt; StandardizeUrl(blog.Url).Contains(&quot;dotnet&quot;)).ToList();  public static string StandardizeUrl(string url) {     url = url.ToLower();     if (!url.StartsWith(&quot;http:\/\/&quot;))     {         url = string.Concat(&quot;http:\/\/&quot;, url);     }     return url; } <\/code><\/pre>\n<p>  <u>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/u><\/p>\n<pre><code class=\"cs\">var blogs = context.Blogs.AsEnumerable().Where(blog =&gt; StandardizeUrl(blog.Url).Contains(&quot;dotnet&quot;)).ToList();   \/\/\u0415\u0449\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0439 \u0442\u0430\u043a var blogs = context.Blogs.Where(blog =&gt; blog.Contains(&quot;dotnet&quot;))     .OrderByDescending(blog =&gt; blog.Rating)     .Select(blog =&gt; new     {         Id = blog.BlogId,         Url = StandardizeUrl(blog.Url)     })     .ToList(); <\/code><\/pre>\n<p>  \u0412\u0430\u0443, \u0432\u0430\u0443, \u0432\u0430\u0443, \u0440\u0430\u0437\u043e\u0433\u043d\u0430\u043b\u0441\u044f.<\/p>\n<p>  \u0421\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0441\u0432\u0435\u0436\u0438\u0442\u044c \u0437\u043d\u0430\u043d\u0438\u044f \u043f\u043e \u043c\u0435\u0442\u043e\u0434\u0430\u043c LINQ.<\/p>\n<h4>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u043c\u0435\u0436\u0434\u0443 <i>ToList <\/i><i><i>AsEnumerable <\/i><\/i>AsQueryable<\/h4>\n<p>  \u0418\u0442\u0430\u043a, <i>ToList<\/i><\/p>\n<ul>\n<li>\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e.<\/li>\n<li>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <i>.ToList()<\/i> \u0434\u043b\u044f \u0444\u043e\u0440\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 \u0440\u0435\u0436\u0438\u043c\u0430 \u043f\u043e\u0437\u0434\u043d\u0435\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 (lazy loading), \u0442\u0430\u043a \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u0432\u044b \u043f\u0440\u043e\u0439\u0434\u0435\u0442\u0435\u0441\u044c \u043f\u043e \u0434\u0430\u043d\u043d\u044b\u043c.<\/li>\n<\/ul>\n<p>  <i>AsEnumerable<\/i><\/p>\n<ul>\n<li>\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0441 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u043e\u0439 (lazy loading)<\/li>\n<li>\u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440: <i>Func &lt;TSource, bool&gt;<\/i><\/li>\n<li>\u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u0442 \u0435\u0433\u043e (\u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 <b>Where\/Take\/Skip<\/b> \u043f\u0440\u0438\u0432\u0435\u0434\u0443\u0442 \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u043f\u0440\u043e\u0441 select * from Table1, <\/li>\n<li>\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043d\u0430\u0431\u043e\u0440 \u0432 \u043f\u0430\u043c\u044f\u0442\u044c, \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u0431\u0435\u0440\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u0435 N \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432)<\/li>\n<li>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u0442 \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u0445\u0435\u043c\u0430: <i>Linq-to-SQL + Linq-to-Object<\/i>.<\/li>\n<li>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <i>IEnumerable <\/i>\u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043f\u043e\u0437\u0434\u043d\u0435\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 (lazy loading).<\/li>\n<\/ul>\n<p>  <i>AsQueryable<\/i><\/p>\n<ul>\n<li>\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0441 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u043e\u0439 (lazy loading)<\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/ru-ru\/dotnet\/api\/system.linq.queryable.asqueryable?view=netframework-4.8#System_Linq_Queryable_AsQueryable__1_System_Collections_Generic_IEnumerable___0__\" rel=\"nofollow\">\u041c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d:<\/a>\n<pre><code class=\"cs\">AsQueryable(IEnumerable) \u0438\u043b\u0438 AsQueryable&lt;TElement&gt;(IEnumerable&lt;TElement&gt;) <\/code><\/pre>\n<p>  <\/li>\n<li>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 Expression \u0432 T-SQL (\u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0438 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430), \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/li>\n<li>\u0412\u043e\u0442 \u043f\u043e\u0447\u0435\u043c\u0443 DbSet (\u0432 Entity Framework) \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 AsQueryable \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b.<\/li>\n<li>\u041d\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0435\u0441\u043b\u0438 <b>Take(5)<\/b> \u044d\u0442\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u0438\u0434\u0430 <b>\u00abselect top 5 * SQL\u00bb<\/b> \u0432 \u0444\u043e\u043d\u043e\u0432\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u0431\u043e\u043b\u0435\u0435 \u0434\u0440\u0443\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0434\u043b\u044f SQL \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u0434\u0430\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u043d\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.\u0422\u0430\u043a \u0447\u0442\u043e <i>AsQueryable()<\/i> \u043e\u0431\u044b\u0447\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0435\u043c <i>AsEnumerable()<\/i> \u0442\u0430\u043a \u043a\u0430\u043a \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 T-SQL \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0438\u0439 \u0432 \u0441\u0435\u0431\u044f \u0432\u0441\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f Linq \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0435 \u0432\u0430\u043c\u0438.<\/li>\n<li>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <i>AsQueryable <\/i>\u0435\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u043b\u0443\u0447\u0448\u0435\u043d \u043f\u0435\u0440\u0435\u0434 \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/li>\n<\/ul>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f AsQueryable \u0432 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435:<\/p>\n<pre><code class=\"cs\">public IEnumerable&lt;EmailView&gt; GetEmails(out int totalRecords, Guid? deviceWorkGroupID,                 DateTime? timeStart, DateTime? timeEnd, string search, int? confirmStateID, int? stateTypeID, int? limitOffset, int? limitRowCount, string orderBy, bool desc)         {             var r = new List&lt;EmailView&gt;();              using (var db = new GJobEntities())             {                 var query = db.Emails.AsQueryable();                  if (timeStart != null &amp;&amp; timeEnd != null)                 {                     query = query.Where(p =&gt; p.Created &gt;= timeStart &amp;&amp; p.Created &lt;= timeEnd);                 }                  if (stateTypeID != null &amp;&amp; stateTypeID &gt; -1)                 {                     query = query.Where(p =&gt; p.EmailStates.OrderByDescending(x =&gt; x.AtTime).FirstOrDefault().EmailStateTypeID == stateTypeID);                 }                   if (confirmStateID != null &amp;&amp; confirmStateID &gt; -1)                 {                     var boolValue = confirmStateID == 1 ? true : false;                     query = query.Where(p =&gt; p.IsConfirmed == boolValue);                 }                  if (!string.IsNullOrEmpty(search))                 {                     search = search.ToLower();                     query = query.Where(p =&gt; (p.Subject + &quot; &quot; + p.CopiesEmails + &quot; &quot; + p.ToEmails + &quot; &quot; + p.FromEmail + &quot; &quot; + p.Body)                                         .ToLower().Contains(search));                 }                  if (deviceWorkGroupID != Guid.Empty)                 {                     query = query.Where(x =&gt; x.SCEmails.FirstOrDefault().SupportCall.Device.DeviceWorkGroupDevices.FirstOrDefault(p =&gt; p.DeviceWorkGroupID == deviceWorkGroupID) != null);                 }                  totalRecords = query.Count();                 query = query.OrderByDescending(p =&gt; p.Created);                 if (limitOffset.HasValue)                 {                     query = query.Skip(limitOffset.Value).Take(limitRowCount.Value);                 }                 var items = query.ToList(); \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432\u0441\u0435 \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u0438                  foreach (var item in items)                 {                     var n = new EmailView                     {                         ID = item.ID,                         SentTime = item.SentTime,                         IsConfirmed = item.IsConfirmed,                         Number = item.Number,                         Subject = item.Subject,                         IsDeleted = item.IsDeleted,                         ToEmails = item.ToEmails,                         Created = item.Created,                         CopiesEmails = item.CopiesEmails,                         FromEmail = item.FromEmail,                     };                      \/\/ \u0414\u0440\u0443\u0433\u043e\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430-\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f                       r.Add(n);                 }             }              return r;         } <\/code><\/pre>\n<h4>\u0412\u043e\u043b\u0448\u0435\u0431\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f<\/h4>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043c\u0435\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <i>.AsNoTracking() <\/i> \u043c\u0435\u0442\u043e\u0434.<\/p>\n<p>  <i>\u041c\u0435\u0434\u043b\u0435\u043d\u043d\u0430\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0430<\/i><\/p>\n<pre><code class=\"cs\">var blogs = context.Blogs.ToList();<\/code><\/pre>\n<p>  <i>\u0411\u044b\u0441\u0442\u0440\u0430\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0430 (\u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435)<\/i><\/p>\n<pre><code class=\"cs\">var blogs = context.Blogs.AsNoTracking().ToList();<\/code><\/pre>\n<p>  \u0427\u0443\u0432\u0441\u0442\u0432\u0443\u044e, \u0432\u044b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u0436\u0435 \u0440\u0430\u0437\u043c\u044f\u043b\u0438\u0441\u044c? <\/p>\n<h4>\u0422\u0438\u043f\u044b \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/h4>\n<p>  \u0414\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u0437\u0430\u0431\u044b\u043b, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 <i>lazy loading<\/i>.<\/p>\n<p>  \u041b\u0435\u043d\u0438\u0432\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430<i> (Lazy loading)<\/i> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u044e\u0442\u0441\u044f \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0443 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0447\u0438\u0442\u0430\u0435\u043c <a href=\"https:\/\/docs.microsoft.com\/en-us\/ef\/core\/querying\/related-data\" rel=\"nofollow\">\u0442\u0443\u0442 <\/a>.<\/p>\n<p>  \u0418 \u0437\u0430\u043e\u0434\u043d\u043e, \u043d\u0430\u043f\u043e\u043c\u043d\u044e \u043e \u0434\u0440\u0443\u0433\u0438\u0445 \u0442\u0438\u043f\u0430\u0445 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  \u0410\u043a\u0442\u0438\u0432\u043d\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 <i>(Eager loading)<\/i> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u044e\u0442\u0441\u044f \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u044c \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n<pre><code class=\"cs\">using (var context = new BloggingContext()) {     var blogs = context.Blogs         .Include(blog =&gt; blog.Posts)             .ThenInclude(post =&gt; post.Author)                 .ThenInclude(author =&gt; author.Photo)         .Include(blog =&gt; blog.Owner)             .ThenInclude(owner =&gt; owner.Photo)         .ToList(); } <\/code><\/pre>\n<p>  \u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435! \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 EF Core 3.0.0, \u043a\u0430\u0436\u0434\u043e\u0435 Include \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e <i>JOIN <\/i>\u043a \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c SQL, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u043c \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u0441\u0442\u0430\u0432\u0449\u0438\u043a\u0430\u043c\u0438, \u0442\u043e\u0433\u0434\u0430 \u043a\u0430\u043a \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b SQL. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u0430\u0448\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0432 \u043b\u0443\u0447\u0448\u0443\u044e \u0438\u043b\u0438 \u0432 \u0445\u0443\u0434\u0448\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0437\u0430\u043f\u0440\u043e\u0441\u044b LINQ \u0441 \u0447\u0440\u0435\u0437\u0432\u044b\u0447\u0430\u0439\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u0447\u0438\u0441\u043b\u043e\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0437\u0431\u0438\u0442\u044b \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 LINQ.<\/p>\n<p>  \u042f\u0432\u043d\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430<i> (Explicit loading)<\/i> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u044f\u0432\u043d\u043e \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u044e\u0442\u0441\u044f \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0437\u0434\u043d\u0435\u0435.<\/p>\n<pre><code class=\"cs\">using (var context = new BloggingContext()) {     var blog = context.Blogs         .Single(b =&gt; b.BlogId == 1);      var goodPosts = context.Entry(blog)         .Collection(b =&gt; b.Posts)         .Query()         .Where(p =&gt; p.Rating &gt; 3)         .ToList(); }<\/code><\/pre>\n<p>  \u0420\u044b\u0432\u043e\u043a \u0438 \u043f\u0440\u043e\u0440\u044b\u0432! \u0414\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435? <\/p>\n<h4>\u0413\u043e\u0442\u043e\u0432\u044b \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c\u0441\u044f \u0435\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435?<\/h4>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0437\u043a\u043e \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0432\u044b\u0431\u043e\u0440\u043a\u0435 \u0441\u043b\u043e\u0436\u043d\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0438 \u0434\u0430\u0436\u0435 \u043d\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f (1) \u0438\u043b\u0438 \u0447\u0442\u043e \u0435\u0449\u0435 \u043b\u0443\u0447\u0448\u0435 \u2013 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0435(\u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435) \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u043b\u043e\u0441\u043a\u043e\u0439 \u0444\u043e\u0440\u043c\u0435 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f (2).<\/p>\n<p>  (1) <b>\u0418\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435<\/b> \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 MS SQL Server<\/p>\n<p>  \u0418\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u0435\u0442 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441. \u0423\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 SQL Server \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f, \u043a\u0430\u043a \u0438 \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441. \u0418\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0442\u0440\u043e\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043b\u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0441\u0442\u0440\u043e\u043a. <\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043d\u0430 \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u043e \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0441\u043e\u0437\u0434\u0430\u0432 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f. \u0414\u043b\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0431\u043e\u0440 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043d\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u043d\u0430\u0431\u043e\u0440 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c. \u0417\u0430\u043f\u0440\u043e\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u043c\u043e\u0433\u0443\u0442 \u0434\u0430\u0436\u0435 \u0432\u044b\u0438\u0433\u0440\u0430\u0442\u044c \u043e\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0438\u0437 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f. <\/p>\n<p>  \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0438\u043c\u0435\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0432 \u0432\u0438\u0434\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u0415\u0441\u043b\u0438 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445, SQL Server \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0432 \u044d\u0442\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438. \u0412 \u0440\u0435\u0434\u0430\u043a\u0446\u0438\u044f\u0445 SQL Server \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0438 \u043f\u0440\u0435\u0434\u043f\u0440\u0438\u044f\u0442\u0438\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439 \u0434\u043b\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0432\u044b\u043f\u0443\u0441\u043a\u0430\u0445 SQL Server \u0437\u0430\u043f\u0440\u043e\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0443 NOEXPAND, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u043e\u0442 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0432 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438.<\/p>\n<p>  (2) \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441, \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0439 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u0435\u0435 \u0442\u0440\u0435\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u0432 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0440\u0438 \u0438 \u0431\u043e\u043b\u0435\u0435 c \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u043d\u043e\u0439 <b>CRUD <\/b>\u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439, \u043b\u0443\u0447\u0448\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0434\u0443\u043c\u0430\u0442\u044c\u0441\u044f \u043e \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043d\u0430\u0431\u043e\u0440, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0435\u0433\u043e \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u0438\u043c\u0435\u0442\u044c <b>Primary Key \u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043f\u043e \u043f\u043e\u043b\u044f\u043c \u043f\u043e\u0438\u0441\u043a\u0430 \u0432 LINQ<\/b>.<\/p>\n<h4>\u0427\u0442\u043e \u043d\u0430\u0441\u0447\u0435\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u0438?<\/h4>\n<p>  \u0414\u0430! \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0435\u0435 \u0433\u0434\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0436\u043d\u043e! \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"cs\">public void Do() {     var myTask = GetFederalDistrictsAsync ();     foreach (var item in myTask.Result)     {          \/\/\u0412\u0430\u0448 \u043a\u043e\u0434     } }  public async Task&lt;List&lt;FederalDistrict&gt;&gt; GetFederalDistrictsAsync() {     var conn = configurationRoot.GetConnectionString(&quot;EFCoreTestContext&quot;);     optionsBuilder.UseSqlServer(conn);     using var context = new EFCoreTestContext(optionsBuilder.Options);     return await context.FederalDistricts.ToListAsync(); } <\/code><\/pre>\n<p>  \u0418 \u0434\u0430, \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0437\u0430\u0431\u044b\u043b\u0438 \u0434\u043b\u044f \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438? \u0411\u0443\u0443\u0443\u043c! <\/p>\n<pre><code class=\"cs\">return await context.FederalDistricts.&lt;b&gt;AsNoTracking()&lt;\/b&gt;.ToListAsync();<\/code><\/pre>\n<p>  \u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435: \u043c\u0435\u0442\u043e\u0434 <b>Do()<\/b> \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0434\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0446\u0435\u043b\u0435\u0439 \u0442\u043e\u043b\u044c\u043a\u043e, \u0441 \u0446\u0435\u043b\u044c\u044e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u0430 <b>GetFederalDistrictsAsync()<\/b>. \u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438 \u043c\u043e\u0438 \u043a\u043e\u043b\u043b\u0435\u0433\u0438 \u0442\u0443\u0442\u043d\u0443\u0436\u0435\u043d \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0447\u0438\u0441\u0442\u043e\u0439 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>  \u0418 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u044f \u0435\u0433\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u043d\u044f\u0442\u0438\u044f <a href=\"https:\/\/docs.microsoft.com\/ru-ru\/aspnet\/core\/mvc\/views\/view-components?view=aspnetcore-3.1\" rel=\"nofollow\">\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432 ASP .NET Core<\/a>:<\/p>\n<pre><code class=\"cs\">\/\/ \u041a\u043b\u0430\u0441\u0441 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 public class PopularPosts : ViewComponent     {         private readonly IStatsRepository _statsRepository;          public PopularPosts(IStatsRepository statsRepository)         {             _statsRepository = statsRepository;         }          public async Task&lt;IViewComponentResult&gt; InvokeAsync()         {            \/\/ \u0412\u044b\u0437\u043e\u0432 \u043d\u0430\u0448\u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0431\u0435\u0437 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0438\u0437 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438             var federalDistricts = await _statsRepository.GetFederalDistrictsAsync();              var model = new TablePageModel()             {                 FederalDistricts = federalDistricts,             };              return View(model);         }     }     \/\/ \u0414\u0430\u043b\u0435\u0435          \/\/\/ &lt;summary&gt;     \/\/\/ \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0445\u043c\u043c\u043c.... \u0447\u0435\u0433\u043e-\u043b\u0438\u0431\u043e     \/\/\/ &lt;\/summary&gt;     public interface IStatsRepository     {         \/\/\/ &lt;summary&gt;         \/\/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0444\u0435\u0434\u0435\u0440\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u043a\u0440\u0443\u0433\u043e\u0432 \u0438 \u0438\u0445 \u0441\u0443\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0444\u0435\u0434\u0435\u0440\u0430\u0446\u0438\u0438         \/\/\/ &lt;\/summary&gt;         \/\/\/ &lt;returns&gt;&lt;\/returns&gt;         IEnumerable&lt;FederalDistrict&gt; FederalDistricts();          \/\/\/ &lt;summary&gt;         \/\/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0444\u0435\u0434\u0435\u0440\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u043a\u0440\u0443\u0433\u043e\u0432 \u0438 \u0438\u0445 \u0441\u0443\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0444\u0435\u0434\u0435\u0440\u0430\u0446\u0438\u0438 \t\/\/\/ \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e!!!         \/\/\/ &lt;\/summary&gt;         \/\/\/ &lt;returns&gt;&lt;\/returns&gt;         Task&lt;List&lt;FederalDistrict&gt;&gt; GetFederalDistrictsAsync();     }\t \t     \/\/\/ &lt;summary&gt;     \/\/\/ \u0411\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0445\u043c\u043c\u043c.... \u0447\u0435\u0433\u043e-\u043b\u0438\u0431\u043e     \/\/\/ &lt;\/summary&gt;     public class StatsRepository : IStatsRepository     {         private readonly DbContextOptionsBuilder&lt;EFCoreTestContext&gt;             optionsBuilder = new DbContextOptionsBuilder&lt;EFCoreTestContext&gt;();         private readonly IConfigurationRoot configurationRoot;          public StatsRepository()         {             IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()                     .SetBasePath(Environment.CurrentDirectory)                     .AddJsonFile(&quot;appsettings.json&quot;, optional: true, reloadOnChange: true);             configurationRoot = configurationBuilder.Build();         }          public async Task&lt;List&lt;FederalDistrict&gt;&gt; GetFederalDistrictsAsync()         {             var conn = configurationRoot.GetConnectionString(&quot;EFCoreTestContext&quot;);             optionsBuilder.UseSqlServer(conn);             using var context = new EFCoreTestContext(optionsBuilder.Options);             return await context.FederalDistricts.Include(x =&gt; x.FederalSubjects).ToListAsync();         }          public IEnumerable&lt;FederalDistrict&gt; FederalDistricts()         {             var conn = configurationRoot.GetConnectionString(&quot;EFCoreTestContext&quot;);             optionsBuilder.UseSqlServer(conn);              using var ctx = new EFCoreTestContext(optionsBuilder.Options);             return ctx.FederalDistricts.Include(x =&gt; x.FederalSubjects).ToList();         }     }     \/\/ \u0412\u044b\u0437\u043e\u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 Home\\Index      &lt;div id=&quot;tableContainer&quot;&gt;             @await Component.InvokeAsync(&quot;PopularPosts&quot;)      &lt;\/div&gt;   \/\/ \u0410 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e HTML \u0441 \u043c\u043e\u0434\u0435\u043b\u044e \u043f\u043e \u043f\u0443\u0442\u0438  Shared\\Components\\PopularPosts\\Default.cshtml  <\/code><\/pre>\n<p>  \u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432 Entity Framework Core.<\/p>\n<p>  \u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 LINQ \u0432\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438. \u0417\u0430\u043f\u0440\u043e\u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432.<\/p>\n<p>  \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u044b \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<ul>\n<li>\u0418\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0432 \u0446\u0438\u043a\u043b\u0435 for.<\/li>\n<li>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 ToList, ToArray, Single, Count.<\/li>\n<li>\u041f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0443.<\/li>\n<\/ul>\n<p>  <\/p>\n<h4>\u041a\u0430\u043a \u0436\u0435 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 EF Core \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f?<\/h4>\n<p>  (1) C \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u0434 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0432\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u044b\u043b \u0438\u0437\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u043d \/ \u043e\u0442\u0434\u0435\u043b\u0435\u043d \u0432 \u0447\u0435\u0442\u043a\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435 (\u0432 \u0438\u0437\u043e\u043b\u044f\u0446\u0438\u0438). \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u0439\u0442\u0438 \u043a\u043e\u0434 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>  (2) \u041d\u0435 \u0441\u043c\u0435\u0448\u0438\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0432\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0447\u0430\u0441\u0442\u044f\u043c\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0442\u0430\u043a\u0438\u043c\u0438 \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0438\u043b\u0438 API. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043a\u043e\u0434 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c, \u043d\u0435 \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u044f\u0441\u044c \u043e \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u0445, \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445. <\/p>\n<h4>\u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0438 \u0431\u044b\u0441\u0442\u0440\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <i>SaveChanges<\/i>?<\/h4>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u043d\u0443 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043d\u0430 \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0441\u0438.<\/p>\n<p>  <i>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e<\/i><\/p>\n<pre><code class=\"cs\">using(var db = new NorthwindEntities()) { var transaction = db.Database.BeginTransaction();  try {     \/\/ \u0412\u0441\u0442\u0430\u0432\u043a\u0430 \u0437\u0430\u043f\u0438\u0441\u0438 1     var  obj1 = new Customer();     obj1.CustomerID = &quot;ABCDE&quot;;     obj1.CompanyName = &quot;Company 1&quot;;     obj1.Country = &quot;USA&quot;;     db.Customers.Add(obj1);    \/\/\u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043f\u0435\u0440\u0432\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c        db.SaveChanges();      \/\/ \u0412\u0441\u0442\u0430\u0432\u043a\u0430 \u0437\u0430\u043f\u0438\u0441\u0438 2     var  obj2 = new Customer();     obj2.CustomerID = &quot;PQRST&quot;;     obj2.CompanyName = &quot;Company 2&quot;;         obj2.Country = &quot;USA&quot;;     db.Customers.Add(obj2);      \/\/ \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432\u0442\u043e\u0440\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c     db.SaveChanges();      transaction.Commit(); } catch {     transaction.Rollback(); } } <\/code><\/pre>\n<p>  <i>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e<\/i><\/p>\n<pre><code class=\"cs\">using(var db = new NorthwindEntities()) { var transaction = db.Database.BeginTransaction();  try {    \/\/\u0412\u0441\u0442\u0430\u0432\u043a\u0430 \u0437\u0430\u043f\u0438\u0441\u0438 1     var  obj1 = new Customer();     obj1.CustomerID = &quot;ABCDE&quot;;     obj1.CompanyName = &quot;Company 1&quot;;     obj1.Country = &quot;USA&quot;;     db.Customers.Add(obj1);       \/\/ \u0412\u0441\u0442\u0430\u0432\u043a\u0430 \u0437\u0430\u043f\u0438\u0441\u0438 2     var  obj2 = new Customer();     obj2.CustomerID = &quot;PQRST&quot;;     obj2.CompanyName = &quot;Company 2&quot;;         obj2.Country = &quot;USA&quot;;     db.Customers.Add(obj2);     \/\/ \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0434\u0432\u0443\u0445 \u0438\u043b\u0438 N \u0437\u0430\u043f\u0438\u0441\u0435\u0439     db.SaveChanges();      transaction.Commit(); } catch {     transaction.Rollback(); } } <\/code><\/pre>\n<p>  \u0412\u0441\u0435\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u043f\u0440\u0430\u0432\u0438\u043b\u0430. \u0415\u0441\u043b\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0439, \u0442\u043e \u0435\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438. \u0410 \u0435\u0449\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0432 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438.<\/p>\n<pre><code class=\"cs\">\/\/ \u0423\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u0434\u0435\u043f\u043e\u0437\u0438\u0442\u0430 \u0435\u0433\u043e \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430 public async Task&lt;IActionResult&gt; AddDepositToHousehold(int householdId, DepositRequestModel model) {     using (var transaction = await Context.Database.BeginTransactionAsync(IsolationLevel.Snapshot))     {         try         {             \/\/ \u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0434\u0435\u043f\u043e\u0437\u0438\u0442 \u0432 \u0411\u0414              var deposit = this.Mapper.Map&lt;Deposit&gt;(model);             await this.Context.Deposits.AddAsync(deposit);              await this.Context.SaveChangesAsync();              \/\/ \u041e\u043f\u043b\u0430\u0442\u0438\u0442\u044c \u0437\u0430\u0434\u043e\u043b\u0436\u043d\u043e\u0441\u0442\u0438 \u0441 \u0434\u0435\u043f\u043e\u0437\u0438\u0442\u0430                var debtsToPay = await this.Context.Debts.Where(d =&gt; d.HouseholdId == householdId &amp;&amp; !d.IsPaid).OrderBy(d =&gt; d.DateMade).ToListAsync();              debtsToPay.ForEach(d =&gt; d.IsPaid = true);              await this.Context.SaveChangesAsync();              \/\/ \u0423\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u0431\u0430\u043b\u0430\u043d\u0441\u0430 \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430             var household = this.Context.Households.FirstOrDefaultAsync(h =&gt; h.Id == householdId);              household.Balance += model.DepositAmount;              await this.Context.SaveChangesAsync();              transaction.Commit();             return this.Ok();         }         catch         {             transaction.Rollback();             return this.BadRequest();         }     } } <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0422\u0440\u0438\u0433\u0433\u0435\u0440\u044b, \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u0435 \u043f\u043e\u043b\u044f, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 EF Core<\/h4>\n<p>  \u0414\u043b\u044f \u0441\u043d\u0438\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u043c EF Core \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u0435 \u043f\u043e\u043b\u044f \u0438 \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u044b \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u043e \u043b\u0443\u0447\u0448\u0435 \u044d\u0442\u0438\u043c \u043d\u0435 \u0443\u0432\u043b\u0435\u043a\u0430\u0442\u044c\u0441\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u0437\u0430\u043f\u0443\u0442\u0430\u043d\u043d\u044b\u043c. \u0410 \u0432\u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u0440\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u0445 \u0432\u044b\u0431\u043e\u0440\u043a\u0438!<\/p>\n<h4>\u041f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c \u0432 EF Core<\/h4>\n<p>  \u0415\u0441\u043b\u0438 \u0442\u044b \u0445\u043e\u0447\u0435\u0448\u044c \u0432\u0441\u0435 \u0437\u0430\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0442\u044c \u0447\u0442\u043e\u0431\u044b \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c\u0441\u044f, \u0442\u043e \u043e\u0431\u043b\u043e\u043c\u0438\u0441\u044c: EF Core \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432 \u043e\u0434\u043d\u043e\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430. \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u043e\u0434\u043e\u0436\u0434\u0430\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e await \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438.<\/p>\n<p>  EF Core \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0442\u043e\u043a\u0430 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u0430\u0436\u043d\u044b \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u043e\u0442\u043a\u043b\u0438\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0432 \u0442\u043e\u043b\u0441\u0442\u044b\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u0445. \u041e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0442\u0430\u043a\u0436\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u0443\u044e \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0432 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u0433\u0434\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442\u044c \u043f\u043e\u0442\u043e\u043a \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"cs\">public async Task&lt;List&lt;Blog&gt;&gt; GetBlogsAsync() {     using (var context = new BloggingContext())     {         return await context.Blogs.ToListAsync();     } }<\/code><\/pre>\n<p>  <\/p>\n<h4>\u0410 \u0447\u0442\u043e \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435 \u043f\u0440\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b LINQ?<\/h4>\n<p>  \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u043e \u043f\u043e\u0445\u043e\u0436\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432 Entity Framework, \u0432\u044b \u0447\u0430\u0441\u0442\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u044f \u0437\u0430\u043f\u0440\u043e\u0441 \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044f \u0435\u0433\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c \u0433\u043e\u0440\u043e\u0434\u0435; \u0433\u043e\u0440\u043e\u0434 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0432 \u0444\u043e\u0440\u043c\u0435. LINQ to Entities \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0446\u0435\u043b\u0438 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<p>  \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 .NET Framework 4.5, \u0437\u0430\u043f\u0440\u043e\u0441\u044b LINQ \u043a\u044d\u0448\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0432\u044b \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b LINQ, \u0447\u0442\u043e\u0431\u044b \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u044d\u0442\u0443 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f\u0445, \u0438 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u043c\u0438, \u0447\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u044b LINQ, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043a\u044d\u0448\u0438\u0440\u0443\u044e\u0442\u0441\u044f. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u044b LINQ to Entities, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 Enumerable.Contains \u043a \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f\u043c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u043d\u0435 \u043a\u044d\u0448\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438. \u0422\u0430\u043a\u0436\u0435 \u043d\u0435 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0439 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 LINQ.<\/p>\n<p>  \u041c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/framework\/data\/adonet\/ef\/language-reference\/compiled-queries-linq-to-entities\" rel=\"nofollow\">\u0442\u0443\u0442<\/a>. <\/p>\n<h4>\u041d\u0435 \u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043e\u0432 DbContext!<\/h4>\n<p>  \u0412 \u043e\u0431\u0449\u0435\u043c \u0442\u0430\u043a, \u044f \u0437\u043d\u0430\u044e \u043c\u043d\u043e\u0433\u0438\u0435 \u0438\u0437 \u0432\u0430\u0441, \u0435\u0441\u043b\u0438 \u043d\u0435 \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u2014 lazy f_u__c_k__e_r__s \u0438 \u0432\u0441\u044e \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u044b \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u0442\u0435 \u0432 \u043e\u0434\u0438\u043d \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u043f\u043e\u0434\u0445\u043e\u0434\u0430 Database-First. \u0418 \u0437\u0440\u044f \u0432\u044b \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0435! \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430\u043c\u0438 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u044d\u0442\u043e \u043c\u0438\u043d\u0443\u0441. \u0422\u0430\u043a \u0438\u043b\u0438 \u0438\u043d\u0430\u0447\u0435 \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0431\u043e\u043b\u0435\u0435 50 \u0442\u0430\u0431\u043b\u0438\u0446 \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c \u043e \u0435\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0438.<\/p>\n<h4>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0438 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 (pooling DdContext)<\/h4>\n<p>  \u0421\u043c\u044b\u0441\u043b \u043f\u0443\u043b\u0430 <b>DbContext <\/b>\u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 <b>DbContext <\/b>\u0438\u0437 \u043f\u0443\u043b\u0430, \u0447\u0442\u043e \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c \u043d\u043e\u0432\u043e\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437. \u042d\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043f\u0440\u0438\u0447\u0438\u043d\u043e\u0439 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0443\u043b\u0430 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0432 ADO.NET, \u0445\u043e\u0442\u044f \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0442\u044f\u0436\u0435\u043b\u044b\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u043c.<\/p>\n<pre><code class=\"cs\">using System; using System.Diagnostics; using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection;  namespace Demos {     public class Blog     {         public int BlogId { get; set; }         public string Name { get; set; }         public string Url { get; set; }     }      public class BloggingContext : DbContext     {         public static long InstanceCount;          public BloggingContext(DbContextOptions options)             : base(options)             =&gt; Interlocked.Increment(ref InstanceCount);          public DbSet&lt;Blog&gt; Blogs { get; set; }     }      public class BlogController     {         private readonly BloggingContext _context;          public BlogController(BloggingContext context) =&gt; _context = context;          public async Task ActionAsync() =&gt; await _context.Blogs.FirstAsync();     }      public class Startup     {         private const string ConnectionString             = @&quot;Server=(localdb)\\mssqllocaldb;Database=Demo.ContextPooling;Integrated Security=True;ConnectRetryCount=0&quot;;          public void ConfigureServices(IServiceCollection services)         {             services.AddDbContext&lt;BloggingContext&gt;(c =&gt; c.UseSqlServer(ConnectionString));         }     }      public class Program     {         private const int Threads = 32;         private const int Seconds = 10;          private static long _requestsProcessed;          private static async Task Main()         {             var serviceCollection = new ServiceCollection();             new Startup().ConfigureServices(serviceCollection);             var serviceProvider = serviceCollection.BuildServiceProvider();              SetupDatabase(serviceProvider);              var stopwatch = new Stopwatch();              MonitorResults(TimeSpan.FromSeconds(Seconds), stopwatch);              await Task.WhenAll(                 Enumerable                     .Range(0, Threads)                     .Select(_ =&gt; SimulateRequestsAsync(serviceProvider, stopwatch)));         }          private static void SetupDatabase(IServiceProvider serviceProvider)         {             using (var serviceScope = serviceProvider.CreateScope())             {                 var context = serviceScope.ServiceProvider.GetService&lt;BloggingContext&gt;();                  if (context.Database.EnsureCreated())                 {                     context.Blogs.Add(new Blog { Name = &quot;The Dog Blog&quot;, Url = &quot;http:\/\/sample.com\/dogs&quot; });                     context.Blogs.Add(new Blog { Name = &quot;The Cat Blog&quot;, Url = &quot;http:\/\/sample.com\/cats&quot; });                     context.SaveChanges();                 }             }         }         private static async Task SimulateRequestsAsync(IServiceProvider serviceProvider, Stopwatch stopwatch)         {             while (stopwatch.IsRunning)             {                 using (var serviceScope = serviceProvider.CreateScope())                 {                     await new BlogController(serviceScope.ServiceProvider.GetService&lt;BloggingContext&gt;()).ActionAsync();                 }                  Interlocked.Increment(ref _requestsProcessed);             }         }          private static async void MonitorResults(TimeSpan duration, Stopwatch stopwatch)         {             var lastInstanceCount = 0L;             var lastRequestCount = 0L;             var lastElapsed = TimeSpan.Zero;              stopwatch.Start();              while (stopwatch.Elapsed &lt; duration)             {                 await Task.Delay(TimeSpan.FromSeconds(1));                  var instanceCount = BloggingContext.InstanceCount;                 var requestCount = _requestsProcessed;                 var elapsed = stopwatch.Elapsed;                 var currentElapsed = elapsed - lastElapsed;                 var currentRequests = requestCount - lastRequestCount;                  Console.WriteLine(                     $&quot;[{DateTime.Now:HH:mm:ss.fff}] &quot;                     + $&quot;Context creations\/second: {instanceCount - lastInstanceCount} | &quot;                     + $&quot;Requests\/second: {Math.Round(currentRequests \/ currentElapsed.TotalSeconds)}&quot;);                  lastInstanceCount = instanceCount;                 lastRequestCount = requestCount;                 lastElapsed = elapsed;             }              Console.WriteLine();             Console.WriteLine($&quot;Total context creations: {BloggingContext.InstanceCount}&quot;);             Console.WriteLine(                 $&quot;Requests per second:     {Math.Round(_requestsProcessed \/ stopwatch.Elapsed.TotalSeconds)}&quot;);              stopwatch.Stop();         }<\/code><\/pre>\n<p>  <\/p>\n<h4>\u041a\u0430\u043a \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043b\u0438\u0448\u043d\u0438\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u043f\u0440\u0438 CRUD \u0432 EF Core?<\/h4>\n<p>  \u041d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0432 \u0432\u0441\u0442\u0430\u0432\u043a\u0443 \u0432 \u043e\u0434\u043d\u043e\u043c \u043a\u043e\u0434\u0435. \u0412\u0441\u0435\u0433\u0434\u0430 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0439\u0442\u0435 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\/\u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438 \u0435\u0433\u043e \u0432\u0441\u0442\u0430\u0432\u043a\u0443\/\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435. \u041f\u0440\u043e\u0441\u0442\u043e \u0440\u0430\u0437\u043d\u0435\u0441\u0438\u0442\u0435 \u043f\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c: \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c, \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u0430\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e CRUD \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e.<\/p>\n<h4>\u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u0441\u043e\u0432\u0441\u0435\u043c \u0434\u0435\u043b\u0430 \u043f\u043b\u043e\u0445\u043e \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f?<\/h4>\n<p>  \u041f\u0438\u0432\u043e \u0442\u0443\u0442 \u0442\u043e\u0447\u043d\u043e \u043d\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442. \u0410 \u0432\u043e\u0442 \u0447\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442, \u0442\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0447\u0442\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0440\u0430\u0437\u043d\u0435\u0441\u0435\u043d\u0438\u0435\u043c \u043f\u043e \u0441\u043e\u043a\u0435\u0442\u0430\u043c \u044d\u0442\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439. \u0417\u0430\u0434\u0443\u043c\u0430\u0439\u0442\u0435\u0441\u044c \u043e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/architecture\/patterns\/cqrs\" rel=\"nofollow\">Command and Query Responsibility Segregation (CQRS) pattern<\/a>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435, \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043d\u0430 \u0432\u0441\u0442\u0430\u0432\u043a\u0443 \u0438 \u0447\u0442\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  <i>\u0421\u043a\u043e\u0440\u043e\u0441\u0442\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0432\u0430\u043c, \u0434\u0440\u0443\u0437\u044c\u044f \u0438 \u043a\u043e\u043b\u043b\u0435\u0433\u0438!<\/i><\/div>\n<p> \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\/post\/487734\/\"> https:\/\/habr.com\/ru\/post\/487734\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/487734\/\">\n<h4>\u041d\u0435 \u0431\u0443\u0434\u044c \u0436\u0430\u0434\u0438\u043d\u043e\u0439!<\/h4>\n<p>  \u041f\u0440\u0438 \u0432\u044b\u0431\u043e\u0440\u043a\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u043e \u0440\u043e\u0432\u043d\u043e \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e \u0437\u0430 \u043e\u0434\u0438\u043d \u0440\u0430\u0437. \u041d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0439\u0442\u0435 \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b!<\/p>\n<p>  <u>\u041d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/u><\/p>\n<pre><code class=\"cs\">using var ctx = new EFCoreTestContext(optionsBuilder.Options);                 \/\/ \u041c\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043a\u043e\u043b\u043e\u043d\u043a\u0443 ID \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u043d\u043e \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0438 \u044d\u0442\u043e \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e! ctx.FederalDistricts.Select(x=&gt; new { x.ID, x.Name, x.ShortName }).ToList(); <\/code><\/pre>\n<p>  <u>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e:<\/u><\/p>\n<pre><code class=\"cs\">using var ctx = new EFCoreTestContext(optionsBuilder.Options);   \/\/ \u041c\u044b \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043a\u043e\u043b\u043e\u043d\u043a\u0443 ID \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0438 \u044d\u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e! ctx.FederalDistricts.Select(x=&gt; new { x.Name, x.ShortName }).ToList(); ctx.FederalDistricts.Select(x =&gt; new MyClass { Name = x.Name, ShortName = x.ShortName }).ToList(); <\/code><\/pre>\n<p>  <\/p>\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-298478","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/298478","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=298478"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/298478\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=298478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=298478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=298478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}