2

任何想法如何检索 EnumerableQuery 中的值我想检索“Y”或 Null 以创建、更新、删除列,就像我对 Read 列所做的一样,但不是返回“Y”或 NULL,而是返回为 EnumerableQuery,并且我不知道怎么做

from a in MenuFunctions
where a.Scd == 'R' && a.Ise == 'Y'
select new{
    a.Mcd,
    Read = a.Ise,
    Create = (from b in MenuFunctions
                where b.Pcd== a.Mcd && b.Psc == a.Scd && b.Ise=='Y' && b.Scd =='C'
                select b.Ise),
    Update = (from b in MenuFunctions
                where b.Pcd== a.Mcd && b.Psc == a.Scd && b.Ise=='Y' && b.Scd =='U'
                select b.Ise),
    Delete = (from b in MenuFunctions
                where b.Pcd== a.Mcd && b.Psc == a.Scd && b.Ise=='Y' && b.Scd =='D'
                select b.Ise),
}

结果 在此处输入图像描述

4

1 回答 1

1
from a in MenuFunctions
where a.Scd == 'R' && a.Ise == 'Y'
select new{
    a.Mcd,
    Read = a.Ise,
    Create = (from b in MenuFunctions
                where b.Pcd== a.Mcd && b.Psc == a.Scd && b.Ise=='Y' && b.Scd =='C'
                select b.Ise).firstOrDefault() == null ? "N" : "Y",
    Update = (from b in MenuFunctions
                where b.Pcd== a.Mcd && b.Psc == a.Scd && b.Ise=='Y' && b.Scd =='U'
                select b.Ise).firstOrDefault() == null ? "N" : "Y",
    Delete = (from b in MenuFunctions
                where b.Pcd== a.Mcd && b.Psc == a.Scd && b.Ise=='Y' && b.Scd =='D'
                select b.Ise).firstOrDefault() == null ? "N" : "Y",
}

好的,我现在想通了,我需要使用firstOrDefault从中返回值并添加 == null ?"N" : "Y",我还解决了列内的​​空值 :) 但不确定是否有更好的 linq 方法来执行与此相同的功能

于 2013-08-01T05:37:41.360 回答