使用C#从SQL到LINQ [英] SQL to LINQ using C#
本文介绍了使用C#从SQL到LINQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将下面的sql语句转换为linq.但是如何在我的SQL查询中获取ISNULL()区域?
Hi,
I''m trying to convert the below sql statement to linq. But how do i get the ISNULL() area in my SQL query?
SELECT DISTINCT lkpChecks.txtChecksName AS [Check Name],
lkpChecks.intTimeInterval AS [Time Interval],
lkpChecks.intBatchInterval AS [Batch Interval],
lkpChecks.ynStartUp AS [Start Up],
lkpChecks.ynCCP AS [CCP],
lkpChecks.ynBoolean AS [Type Ok/Not Ok],
lkpChecks.txtUnit AS [Unit],
ISNULL(tblChecks.dblMinValue, ISNULL(lkpChecks.dblDefaultMinValue, 0)) AS [Minimum Value],
ISNULL(tblChecks.dblMaxValue, ISNULL(lkpChecks.dblDefaultMaxValue, 0)) AS [Maximum Value],
ISNULL(tblChecks.dblLowerWarningLimit, ISNULL(lkpChecks.dblDefaultMinWarningValue, 0)) AS [Lower Warning Value],
ISNULL(tblChecks.dblUpperWarningLimit, ISNULL(lkpChecks.dblDefaultMaxWarningValue, 0)) AS [Upper Warning Value],
ISNULL(tblChecks.dblTarget, ISNULL(lkpChecks.dblDefaultTargetValue, 0)) AS [Target],
lkpChecks.ynEndFillingCode AS [Get at End of LotCode],
lkpChecks.ynFRReport_Other AS [Include in Release Report],
lkpChecks.intChecks,
lkpChecks.intUserEvent,
ynReqRemarks as [Required Remarks]
FROM lkpChecks LEFT OUTER JOIN tblChecks ON lkpChecks.intChecks = tblChecks.intChecks
AND tblChecks.intProcess = lkpChecks.intProcess
AND tblChecks.intLine = 167
WHERE (lkpChecks.intProcess = 10)
var qs = from check in checksColl
join check_sett in checkSetting
on new
{
cID = check.ChecksID,
cProcess = check.Process
}
equals
new
{
cID = check_sett.CheckID,
cProcess = check_sett.ProcessID
} into temp
from x in temp.Where(line => line.LineID == 10).DefaultIfEmpty()
where check.Process == int.Parse(c_cboProcess.Items[c_cboProcess.SelectedIndex].Key)
select new { CheckName = check.ChecksName,
TimeInterval = check.TimeInterval,
BatchInterval = check.BatchInterval,
Unit = check.Unit
};
上面的linq是可以的,但是当我从"x"添加一些字段时,我会收到此错误对象未设置为对象的实例".
The above linq is ok, but when i add some fields from "x" i''m getting this error "Object is not set to an instance of an object".
select new { CheckName = check.ChecksName,
TimeInterval = check.TimeInterval,
BatchInterval = check.BatchInterval,
Unit = check.Unit,
MinimumValue = x.MinValue,
MaximumValue = x.MaxValue };
感谢您的帮助.
谢谢!!
Appreciate your help.
Thanks!!
推荐答案
添加代码以在x为null时进行更改?这就是SQL的工作.
Add code to change if x is null ? That''s what the SQL is doing.
克里斯蒂安,
感谢您的投入.
如何修复对象未设置为对象的实例" 错误消息?
我无法从"x"中获取值.
谢谢
Hi Christian,
Thanks for your inputs.
How do i fix the "Object is not set to an instance of an object" error message?
I cannot get the value from the "x".
Thanks
这篇关于使用C#从SQL到LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文