如何为sql编写lambda (linq)表达式



我有一个Sql语句,我需要去生成相应的Lambda表达式(Linq)。下面是SQL

Declare @CurrentUserId as int
Declare @CurrentDate as datetime
Set @CurrentDate = GetDate()
Set @CurrentUserId = 1
Select C.conferenceId,C.specialtyId,C.name,C.city,S.abbr as statebbbr,CTRY.name as countryname,C.startdate,C.enddate
from Conferences C
Inner join (
    Select distinct SpecialtyId 
    from UserContent
    Where UserId = @CurrentUserId and DeletedFlag = 0
    ) DT on C.SpecialtyId = DT.SpecialtyId
Left outer join State S on C.StateId = S.StateId
Inner join Country CTRY on C.CountryId = CTRY.CountryId
Where C.DisplayStartDate <= @CurrentDate 
    and C.DisplayEndDate >= @CurrentDate
    and C.DeletedFlag = 0
    and C.Publish = 1
Order by C.startdate ASC

这个的lambda(linq)表达式是什么?

假设数据上下文在变量context

from c in context.conferences
join ctry in context.country on c.CountryId equals ctry.CountryId
join s1 in context.State on c.StateId equals s.StateId into s2
from s in s2.DefaultIfEmpty()
where
  c.DisplayStartDate <= System.DateTime.Now
  && c.DisplayEndDate >= System.DateTime.Now
  && c.DeletedFlag == 0 // or false if represented as a bool
  && c.Publish == 1 // or true if represented as a bool
  && context.UserContent.Any(
                              x => x.SpecialityId == c.specialityId 
                              && x.UserId == currentUserId
                              && x.DeletedFlag == 0 
                              // or if represented as a bool "&& !x.DeletedFlag"
                              )
select new {
      c.ConferenceId,
        c.SpecialtyId,
        c.name,
        c.city,
        stateabbr = s.abbr,
        countryname = ctry.name,
        c.startdate,
        c.enddate
} 

相关内容

  • 没有找到相关文章

最新更新