To convert your SQL query to LINQ in C#, you can use the following LINQ query. Make sure to replace ProjectId
with the actual variable or value you want to use.
مقالات ذات صلة
csharpvar result = (
from ts in Db.Tasks
join prt in Db.ProjectTasks on ts.Id equals prt.TaskId
join tl in Db.Timeline on ts.Id equals tl.TypeId into timelineGroup
from t2 in timelineGroup.DefaultIfEmpty()
join dur in Db.Duration on ts.Id equals dur.TypeId into durationGroup
from t3 in durationGroup.DefaultIfEmpty()
where prt.ProjectId == ProjectId && (t2 == null || t2.Type == (int)Provider.EntityType.TASK) && (t3 == null || t3.Type == (int)Provider.EntityType.TASK)
select new
{
Id = "T" + ts.Id,
ts.Name,
ts.Description,
ts.Priority,
ts.Stage,
ts.Status,
ts.CreatorId,
ProjectId = prt.ProjectId,
StartDate = t2 != null ? t2.StartDate : null,
EndDate = t2 != null ? t2.EndDate : null,
LatestEndDate = t2 != null ? t2.LatestEndDate : null,
LatestStartDate = t2 != null ? t2.LatestStartDate : null,
EarliestStartDate = t2 != null ? t2.EarliestStartDate : null,
ActualStart = t2 != null ? t2.ActualStart : null,
ActualEnd = t2 != null ? t2.ActualEnd : null,
RemTime = t2 != null ? t2.RemTime : null,
ReshowDate = t2 != null ? t2.ReshowDate : null,
Completed = t2 != null ? t2.Completed : null,
ActualDuration = t3 != null ? t3.ActualDuration : null,
ActualDurationPlanned = t3 != null ? t3.ActualDurationPlanned : null
}
).ToList();
This LINQ query will perform the equivalent of your SQL query, including the CONCAT
function and the left joins. It also handles cases where the joined tables may not have matching records, which would result in null values in the corresponding properties of the result objects.
المزيد من المعلومات
الكود السابق يقوم بتحويل الاستعلام SQL الخاص بك إلى استعلام LINQ في C#. هذا الاستعلام يقوم بالتالي:
- يقوم بالانضمام (
join
) بين جدولTasks
وجدولProjectTasks
بناءً على مطابقةId
معTaskId
. - يقوم بالانضمام اليساري (
left join
) بين جدولTasks
وجدولTimelines
بناءً على مطابقةId
معTypeId
ويحد النتائج للحالات حيثType
يساوي 3. - يقوم بالانضمام اليساري (
left join
) بين جدولTasks
وجدولDurations
بناءً على مطابقةId
معTypeId
ويحد النتائج للحالات حيثType
يساوي 3. - يقوم بتحديد العمود الناتج
Id
باستخدام دالةCONCAT
لإضافة حرف “T” قبل قيمةId
من الجدولTasks
. - يحدد الخصائص الأخرى المطلوبة من الجدول
Tasks
والجداول المنضمة مع التعامل مع القيم الفارغة (null
) في حالة عدم وجود تطابق في الجداول المنضمة.
يرجى التأكد من تعديل المتغير ProjectId
في الاستعلام بقيمة فعلية أو متغير يحمل القيمة المطلوبة لتنفيذ الاستعلام بنجاح.