Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# LINQ检查行是否落在日期之间,并且没有间隔_C#_Sql_Linq - Fatal编程技术网

C# LINQ检查行是否落在日期之间,并且没有间隔

C# LINQ检查行是否落在日期之间,并且没有间隔,c#,sql,linq,C#,Sql,Linq,我需要编写一个查询,如果日期介于开始日期和结束日期之间且没有间隔,那么它将只返回行 以下操作将失败且不返回任何内容: Requested -----[---------------------------------]-------- In the DB ----------------[------]------------------------ Requested -----[---------------------------------]-------- In the DB --[

我需要编写一个查询,如果日期介于开始日期和结束日期之间且没有间隔,那么它将只返回行

以下操作将失败且不返回任何内容:

Requested -----[---------------------------------]--------
In the DB ----------------[------]------------------------

Requested -----[---------------------------------]--------
In the DB --[----------------]----------------------------

Requested -----[---------------------------------]--------
In the DB --[----------------]---------[----------------->
下面将传递并返回数据库中的行:

Requested -----[---------------------------------]--------
In the DB -----[---------------------------------]--------

Requested -----[---------------------------------]--------
In the DB --[------------------------------------------]--

Requested -----[---------------------------------]--------
In the DB --[----------------][---------------][--------]-
编辑

下面是表的POCO对象:

public class SubscriptionPeriod
{    
    public int Id { get; set; }
    public int SubscriptionId { get; set; }
    public int? MatchedSubscriptionPeriodId { get; set; }
    public SubscriptionPeriodStatuses Status { get; set; }
    public int Qty { get; set; }
    public int? FillQty { get; set; }
    public DateTime SubscriptionStartDate { get; set; }
    public DateTime? SubscriptionEndDate { get; set; }
    public int? RenewQty { get; set; }
    public bool RollOverQty { get; set; }
    public DateTime? ProcessedDate { get; set; }
    public DateTime CreateDate { get; set; }
}

SubscriptionPeriods
    .Where(sp => sp.Subscription.UserId == userId && 
        sp.Subscription.ZoneId == zoneId && 
        sp.Subscription.Type == 2 && 
        sp.MatchedSubscriptionPeriodId == null && 
        sp.SubscriptionStartDate <= subscriptionEndDate &&
        sp.SubscriptionEndDate >= subscriptionStartDate &&
        (sp.Status == SubscriptionPeriodStatuses.Initalized || sp.Status == SubscriptionPeriodStatuses.Open))
    .Sum(s => (int?)s.Qty)
公共类订阅期
{    
公共int Id{get;set;}
公共int SubscriptionId{get;set;}
public int?MatchedSubscriptionPeriodId{get;set;}
公共订阅周期状态状态{get;set;}
公共整数数量{get;set;}
公共int?FillQty{get;set;}
公共日期时间订阅开始日期{get;set;}
公共日期时间?SubscriptionEndDate{get;set;}
公共整型?更新数量{get;set;}
公共bool滚动数量{get;set;}
公共日期时间?ProcessedDate{get;set;}
公共日期时间CreateDate{get;set;}
}
订阅期
.Where(sp=>sp.Subscription.UserId==UserId&&
sp.Subscription.ZoneId==ZoneId&&
sp.Subscription.Type==2&&
sp.MatchedSubscriptionPeriodId==null&&
sp.SubscriptionStartDate=SubscriptionStartDate&&
(sp.Status==订阅周期状态。初始化| | sp.Status==订阅周期状态。打开))
.Sum(s=>(int?)s.Qty)

注意:当SubscriptionEndDate为
null时
意味着订阅将从开始日期起一直持续。

显示您的类/表是如何定义的。如果我理解正确,您只需要处理SubscriptionEndDate的null值。我说的对吗?@Naveen-如果有空隙,就什么也不返回。