- این خروجی SQL لاگ شده مطلب جاری (با تمام توضیحات و نگاشتهای آن) توسط برنامه مطمئن SQL Server Profiler است:
SELECT
[Extent1].[Id] AS [Id],
[Extent1].[Body] AS [Body],
[Extent1].[ReplyId] AS [ReplyId]
FROM [dbo].[BlogComments] AS [Extent1]
منطقی هم هست. چون در ToList اول، کار با دیتابیس تمام و قطع میشود. ToList دوم سمت کلاینت اجرا میشود. یعنی تشکیل درخت نهایی توسط امکانات LINQ to
Objects انجام میشود و نه هیچ کار اضافهای در سمت سرور.
- اگر اینجا join اضافی پیدا کردید ... حتما مشکلی در تنظیمات نگاشتها دارید.
- اگر duplicate reader دارید شاید بخاطر
lazy loading سایر خواص راهبری است که تعریف کردید مانند User و EditByUser و غیره. اینها اگر قرار است نمایش داده شوند، پیش از ToList اول باید توسط متد الحاقی Include به صورت eager loading تعریف شوند تا lazy loading و duplicate reader نداشته باشید.
- برای فیلتر فیلدهای اضافی، پیش از ToList اول، با استفاده از Projection و نوشتن یک Select، موارد مورد نیاز را انتخاب کنید.