2011-04-09 98 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; 

韓國社交協會