-1

我是 Linq 的新手。我面临一种情况,我必须使用同一服务器的两个不同的数据库表在 LINQ 中进行子查询。

这是我的 sql 查询:

SELECT * FROM DB1.dbo.tbl_inv_emoheader where bln_export = 1 and 
str_destbranch in (SELECT systemcode from DB2.dbo.system_contact where    isnull(rovctrlvan_email,'')!='')

这对我来说可以。

问题 :

我想在 Linq 中进行上述查询。

谢谢

4

1 回答 1

0

在花了一些时间之后,我得到了答案

  List<tbl_inv_emoheader> CheckMsgid = (from EMOheader in InvData.tbl_inv_emoheaders
                                                  where (EMOheader.bln_export == true && (from i in GetEmail() select i).Contains(EMOheader.str_destbranch))
                                                  select EMOheader).ToList();


private static IEnumerable<string> GetEmail()
    {
        List<string> strEmails;
        using (SharedSynchDataContext dc = new SharedSynchDataContext(Connections.Getencompass3()))
        {
            strEmails= (from l in dc.system_contacts
                    where (l.rovctrlvan_email != string.Empty)
                    select l.systemcode).ToList();
        }
        return strEmails;
    }
于 2012-09-26T09:05:03.750 回答