2011-04-09 105 views
1

比较日期时间我试图做到这一点的子查询:LINQ到实体的子查询

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?>' 

我如何能实现这样的查询?
韩国社交协会

回答

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; 

韩国社交协会