Use Linq query to compare date only with DateTime field

后端 未结 7 1319
孤城傲影
孤城傲影 2020-12-20 14:59

I need to compare just the date only in a Linq query that involves a datetime field. However, the syntax below results in the following error message

<

7条回答
  •  再見小時候
    2020-12-20 15:16

    You can do it like bellow:

    var data1 = context.t_quoted_value.Where(x => x.region_name == "Pakistan" 
                            && x.price_date.Value.Year == dt.Year
                            && x.price_date.Value.Month == dt.Month
                            && x.price_date.Value.Day == dt.Day).ToList();
    

提交回复
热议问题