Linq中发生错误在获取日期之间,如何解决? [英] Error Occured in Linq Between when I get the date, How to solve?

查看:62
本文介绍了Linq中发生错误在获取日期之间,如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生,

Dear sir,

Error Occured in Linq getting Between dates when I Write a Query, How to solve this problem?


我的例子是,
传递值: StartDate,EndDate


My Example is,
Passing values : StartDate, EndDate

var myExample=(from ex in db.Office
               where ex.startdate<=StartDate && ex.enddate>=EndDate
select 
{
NoOfBirthdays=((from i in db.Employee where (i.id<100 && i.dob<=StartDate && i.dob>=EndDate)
select i.id).Count())
});


这是我的查询示例,

使用错误/重复记录执行此查询.因为在其中条件仅检查[i.id< 100]而不检查[i.dob< = StartDate&& i.dob> = EndDate]之间的日期条件.

如何解决这个问题?

通过mohan回复我.


this is my example Query,

This Query executed with error/Duplicate records. because inside where condition only check [i.id<100] but not checking [i.dob<=StartDate && i.dob>=EndDate]between date Condition.

How to solve this problem?

By mohan reply me.

推荐答案

我不确定您要归档的内容...
之间"的比较不应该是:
I am not really sure about what you are trying to archive...
shouldn''t the "between" comparison be:
i.dob >= StartDate && i.dob <= EndDate


这样做的方式是搜索出生日期小于/等于开始日期,大于/等于结束日期,因此实际上不在两个日期之间的条目.

抱歉,如果我误解了这个问题.
欢呼声


The way you are doing it you search for entries where the dateofbirth is smaller/equal than the StartDate and greater/equal then the EndDate, so it is actually not between both dates.

Sorry if I misunderstood the question.
cheers


我自己解决了这个查询

错误:条件别名名称错误传递的内部
我将放置外部查询别名,以便解决我的问题

我会与有价值的人见面的下一个问题

来自mohan
i have solved this Query myself

Error: inside where condition alias name passed wrongly
i ll put outside query alias so i solve my problem

i ll meet next Question with valuable one

by from mohan


这篇关于Linq中发生错误在获取日期之间,如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆