Linq to Entities比较Sub Query中的DateTime

时间:2011-04-09 19:24:28

标签: entity-framework-4 linq-to-entities

我正在尝试做这个子查询:

var query = 
    from cjto in oContext.t_table_1
    join cav in oContext.t_table_2 on cjto.cd_code equals cav.cd_code
    where cav.dt_time >= 
        (from tu in oContext.t_table3
        where tu.vl_code == "ABCD"
        select tu.dt_check_time)
    select cav;

然而,我收到错误:

Operator '>=' cannot be applied to operands of type 'System.DateTime' and 'System.Linq.IQueryable<System.DateTime?>'

如何实施此类查询? TKS

1 个答案:

答案 0 :(得分:1)

好的,我明白了......我需要添加FirstOrDefault()所以得到第一个元素

var query = 
    from cjto in oContext.t_table_1
    join cav in oContext.t_table_2 on cjto.cd_code equals cav.cd_code
    where cav.dt_time >= 
        (from tu in oContext.t_table3
        where tu.vl_code == "ABCD"
        select tu.dt_check_time).FirstOrDefault()
    select cav;

韩国社交协会