C# 中的内部联接 sql 查询

本文关键字:sql 查询 内部 | 更新日期: 2023-09-27 17:56:11

我需要将此查询转换为变量,但我很难创建它。我在 c# 查询结束时陷入困境,这就是我所拥有的。我是新手,只是自学成才,所以可能会很远。但这就是我到目前为止所拥有的

var query = (from CON in CONTACT
             join ACT in ACCOUNT on ACT.ACCOUNTID equals CON.ACCOUNTID
             join TTC in TTCONTRACT on TTC.ACCOUNTID equals ACT.ACCOUNTID
             where CON.EMAIL != null && ACT.USERFIELD1 != null &&
                   int.TryParse(ACT.USERFIELD1) = 1 && CON.EMAIL like %@%

下面是原始的 SQL 查询:

Select 
    con.FIRSTNAME, Con.LASTNAME, Con.EMAIL, 
    Act.USERFIELD1 'SerialNumber', ACT.ACCOUNT, 
    TTC.SOFTWAREMAINTENANCE, TTC.HARDWAREMAINTENANCE
from 
    CONTACT CON 
Inner join
    ACCOUNT ACT on ACT.ACCOUNTID = CON.ACCOUNTID 
Inner join
    TTCONTRACTS TTC on TTC.ACCOUNTID = ACT.ACCOUNTID 
Where 
    Con.EMAIL is not null 
    and Act.USERFIELD1 is not null 
    and ISNUMERIC(Act.USERFIELD1) = 1 
    and con.EMAIL like '%@%'

任何帮助将不胜感激 - 谢谢。

C# 中的内部联接 sql 查询

尝试这样的事情:

var b = "Select con.FIRSTNAME, Con.LASTNAME, Con.EMAIL, Act.USERFIELD1 'SerialNumber', ACT.ACCOUNT, TTC.SOFTWAREMAINTENANCE, TTC.HARDWAREMAINTENANCE "+
"from CONTACT CON Inner join ACCOUNT ACT on ACT.ACCOUNTID = CON.ACCOUNTID " +
"Inner join TTCONTRACTS TTC on TTC.ACCOUNTID = ACT.ACCOUNTID " +
"Where Con.EMAIL is not null and Act.USERFIELD1 is not null and " +
"ISNUMERIC(Act.USERFIELD1) = 1 and con.EMAIL like '%@%'";

关于 喜欢 c# 中的运算符等效于包含方法。在查询结束时,您应该指定需要选择的列

var query = from CON in CONTACT     join ACT in ACCOUNT on  ACT.ACCOUNTID equals  CON.ACCOUNTID join TTC in  TTCONTRACT on TTC.ACCOUNTID  equals ACT.ACCOUNTID where  CON.EMAIL != null &&  ACT.USERFIELD1 != null &&  int.TryParse(ACT.USERFIELD1) = 1 &&  CON.EMAIL.Contains("@")
Select {
FIRSTNAME=con.FIRSTNAME,
LASTNAME=Con.LASTNAME,
EMAIL= Con.EMAIL, 
SerialNumber= Act.USERFIELD1 ,
ACCOUNT=ACT.ACCOUNT,
SOFTWAREMAINTENANCE= TTC.SOFTWAREMAINTENANCE,
HARDWAREMAINTENANCE= TTC.HARDWAREMAINTENANCE
}
var query = from CON in CONTACT
             join ACT in ACCOUNT on ACT.ACCOUNTID equals CON.ACCOUNTID
             join TTC in TTCONTRACT on TTC.ACCOUNTID equals ACT.ACCOUNTID
             where CON.EMAIL != null 
                && ACT.USERFIELD1 != null 
                && System.Data.Objects.SqlClient.SqlFunctions.IsNumeric(ACT.USERFIELD1) != null
                && CON.EMAIL.Containt("@")