开发者

Linq to Entities compare DateTime in Sub Query

I'm trying to do this su开发者_Go百科bquery:

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;

However, I get the error:

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

How can I implement such query?

Tks


Ok, I got it... I needed to add the FirstOrDefault() so get the first element

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;

Tks

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜