检查一个日期是否在Date Range-Linq查询之间

vmb*_*vmb 1 .net linq sql-server lambda entity-framework

我将员工的离职信息存储在数据库中.从和日期将存储在DB中.我想阻止员工申请休假,当它已经应用了离开范围时.

例如:假设一名员工已于2015年1月1日至2015年1月5日期间申请休假,

i)if user again try to apply leave for 04/01/2015 to 07/01/2015,then i  need to block that one.
ii)if user again try to apply leave for 05/01/2015 to 05/01/2015,then i  need to block that one.
Run Code Online (Sandbox Code Playgroud)

如何使用Linq查询找到它

dev*_*per 5

你可以尝试如下

    return (from t1 in db.Employee where ( empid == t1.EmplyeeId &&
date1 >= t1.LeaveStart && date2 <= t1.LeaveEnd))
Run Code Online (Sandbox Code Playgroud)

你可以尝试如下,详细的答案

int cntleaves = (from values in dbcontext.User_master
                       where values.iUser_id == Userid &&
                               ((values.dtStart_date >= Startdate &&
                                values.dtEnd_date <= Enddate)
                                 ||
                                 (values.dtStart_date <= Startdate &&
                                values.dtEnd_date <= Enddate))
                       select values).ToList().Count();

        if (cntleaves > 0) {
            ViewBag.Message = "You have already applied for leaves !";            
        }
Run Code Online (Sandbox Code Playgroud)