linq-to-sql – LINQ子查询IN

前端之家收集整理的这篇文章主要介绍了linq-to-sql – LINQ子查询IN前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是IQueryable,lambda表达式和LINQ的新手.我想在子句中放一个子查询,如下所示:

示例代码

SELECT * FROM CLIENT c WHERE c.ETAT IN (
 SELECT DDV_COLUMN_VAL FROM DATA_DICT_VAL
 WHERE TBI_TABLE_NAME = 'CLIENT' AND DD_COLUMN_NAME = 'STATUS'
           AND DDV_COLUMN_VAL_LANG_DSC_1 LIKE ('ac%'))

我如何在LINQ中翻译它?

解决方法

var innerquery = from x in context.DataDictVal
                 where x.TbiTableName == myTableNameVariable
                    && x.DdColumnName == "Status"
                    && x.DdbColumnValLangDsc1.StartsWith("ac")
                 select x.DdvColumnVal;

var query = from c in context.Client
            where innerquery.Contains(c.Etat)
            select c;

猜你在找的MsSQL相关文章