Notice: file_put_contents(): Write of 17069 bytes failed with errno=28 No space left on device in /var/www/tgoop/post.php on line 50
Web Devs@fullStackDevs P.408
FULLSTACKDEVS Telegram 408
#EfCore_Best_Practice

Solve the problem 1+N in Ef Core

حل مشکل 1+N در Ef Core

این مشکل در correlated subqueries رخ میدهد.
به عنوان مثال در کوئری زیر
var query = context.Customers.Select(
c =>
c.Orders.Where(o => o.Amount > 100).Select(o => o.Amount)

);
ابتدا کوئری برای دریافت لیستی از Customers به دیتابیس ارسال میشود .
و به ازای هر Customer کوئری زیر

c.Orders.Where(o => o.Amount > 100).Select(o => o.Amount)
ترجمه و به سمت دیتابیس ارسال میشود.

این مشکل با نام مشکل 1+N شناحته میشود.

از Ef Core 2.1 به بعد Optimization ای برای این قبیل کوئری ها انجام شده است که از وقوع این مشکل جلوگیری میکند و سبب میشود که کوئری بالا حداکثر به دو اس کیو ال کوئری ترجمه شود.
کوئری اول سلکتی برای Customer ها و کوئری دوم اعمال فیلتری بر روی Order ها

برای انجام اینکار هم نیاز به انجام یک تغییر کوچک در کوئری خود دارید.

var query = context.Customers.Select(
c => c.Orders.Where(o => o.Amount > 100).Select(o => o.Amount).ToList());

کافیست به SubQuery خود متد ToList() را اضافه کنید .


اطلاعات بیشتر در مورد این مسئله را می توانید در Issue 4007 مربوط به ریپازیتوری Ef Core مشاهده و دنبال کنید.
@fullStackDevs



tgoop.com/fullStackDevs/408
Create:
Last Update:

#EfCore_Best_Practice

Solve the problem 1+N in Ef Core

حل مشکل 1+N در Ef Core

این مشکل در correlated subqueries رخ میدهد.
به عنوان مثال در کوئری زیر
var query = context.Customers.Select(
c =>
c.Orders.Where(o => o.Amount > 100).Select(o => o.Amount)

);
ابتدا کوئری برای دریافت لیستی از Customers به دیتابیس ارسال میشود .
و به ازای هر Customer کوئری زیر

c.Orders.Where(o => o.Amount > 100).Select(o => o.Amount)
ترجمه و به سمت دیتابیس ارسال میشود.

این مشکل با نام مشکل 1+N شناحته میشود.

از Ef Core 2.1 به بعد Optimization ای برای این قبیل کوئری ها انجام شده است که از وقوع این مشکل جلوگیری میکند و سبب میشود که کوئری بالا حداکثر به دو اس کیو ال کوئری ترجمه شود.
کوئری اول سلکتی برای Customer ها و کوئری دوم اعمال فیلتری بر روی Order ها

برای انجام اینکار هم نیاز به انجام یک تغییر کوچک در کوئری خود دارید.

var query = context.Customers.Select(
c => c.Orders.Where(o => o.Amount > 100).Select(o => o.Amount).ToList());

کافیست به SubQuery خود متد ToList() را اضافه کنید .


اطلاعات بیشتر در مورد این مسئله را می توانید در Issue 4007 مربوط به ریپازیتوری Ef Core مشاهده و دنبال کنید.
@fullStackDevs

BY Web Devs


Share with your friend now:
tgoop.com/fullStackDevs/408

View MORE
Open in Telegram


Telegram News

Date: |

Private channels are only accessible to subscribers and don’t appear in public searches. To join a private channel, you need to receive a link from the owner (administrator). A private channel is an excellent solution for companies and teams. You can also use this type of channel to write down personal notes, reflections, etc. By the way, you can make your private channel public at any moment. During a meeting with the president of the Supreme Electoral Court (TSE) on June 6, Telegram's Vice President Ilya Perekopsky announced the initiatives. According to the executive, Brazil is the first country in the world where Telegram is introducing the features, which could be expanded to other countries facing threats to democracy through the dissemination of false content. Some Telegram Channels content management tips SUCK Channel Telegram Commenting about the court's concerns about the spread of false information related to the elections, Minister Fachin noted Brazil is "facing circumstances that could put Brazil's democracy at risk." During the meeting, the information technology secretary at the TSE, Julio Valente, put forward a list of requests the court believes will disinformation.
from us


Telegram Web Devs
FROM American