如何将SQL Server语句转换为linq语句 [英] How to convert SQL server statement to a linq statement

查看:170
本文介绍了如何将SQL Server语句转换为linq语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SELECT [t1].[TimelineEndDate], [t0].[DateRecieved], [t2].[ConceptName],[t4].MaxTimeLimit
FROM [QualityAssuranceTesting] AS [t0]
LEFT JOIN [ImplementationTimeline] AS [t1] ON [t0].[RequestId] = [t1].[RequestId]
LEFT JOIN [PIP_Concept] AS [t2] ON [t0].[RequestId] = [t2].[RequestId]
LEFT JOIN [ActionHistoryInfo] AS [t3] ON [t2].[RequestId] = [t3].[RequestId]
LEFT JOIN [SlaCategory] AS [t4] ON [t4].SlaLevel = 'Implementation'
Left JOIN [ActionHistoryInfo] AS [t5] ON [t5].ActionTimeStamp BETWEEN '2017-11-06' AND '2017-09-06'





我的尝试:





What I have tried:

from q in QualityAssuranceTestings 
join i in ImplementationTimelines
.where(imple=>imple.RequestId == p.RequestId).DefaultIfEmpty()
join c in PIP_Concepts
.where(concept=>concept.RequestId == i.RequestId).DefaultIfEmpty()
join a in ActionHistoryInfo
.where(action=>action.RequestId == i.RequestId).DefaultIfEmpty()
join s in SlaCategories.where(x=>x.Slalevel == "Implementation") into 
where a.ActionTimeStamp <=new DateTime(2017,09,06) && a.ActionTimeStamp>= new DateTime(2017,11,06)
select new
{
i.TimelineEndDate,
q.DateRecieved,
c.ConceptName,
}

推荐答案

不是真正的答案,但......有一个名为 Linqer 的工具[ ^ ]可以从SQL转换为Linq - 您可以获得试用版,这将使您脱离直接问题。



我发现Linq有时非常令人沮丧,一些SQL函数如DateDiff只是不受支持或者实施起来非常棘手。当我在MVC中遇到这些问题时,将恢复为直接SQL - 请参阅 Entity Framework Raw SQL查询 [ ^ ]



亲切的问候
Not a real answer but... there is a tool called Linqer[^] which can convert from SQL to Linq - you can get a trial which will get you out of your immediate problem.

I have found Linq to be very frustrating at times, some SQL functions such as DateDiff are just not supported or extremely problematic to implement. When I run into these issues in MVC is revert to straight SQL - refer Entity Framework Raw SQL Queries[^]

Kind Regards


这篇关于如何将SQL Server语句转换为linq语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆