Linq - 获取介于下限和上限之间的值

Har*_*oon 1 c# linq

我有一个费用清单(linq到sql实体 - 如果相关) - 高费用,低费用(都是十进制值).我正在通过property value- 比如90000,我想检查这个property值是否与费用列表中的一个(或许多中的一个值)匹配.

费用可能是......

(费用较低 - 费用较高)

0 - 50000
50001 - 75000
75001 - 90000
90001 - 140000
190000 - 500000
Run Code Online (Sandbox Code Playgroud)

在这些值中,90000最适合75001 - 90000频段,所以我想拉出那个FeeDetail实体.我真的不知道使用什么操作符,感谢任何帮助,到目前为止我的代码是...

    [Test]
    public void GetFeeRange()
   {
        const int id = 44;
        var propValue = 90000;

        //get a specific fee entity, then get the range of fee details...
        var recommendedFees = RepoSession.All<Fee>()
            .Where(x =>
                   x.ClientSurveyTypeID == id)
            .GroupJoin(_readOnlySession.All<FeeDetail>(),
                       x => x.FeeID,
                       y => y.FeeID,
                       (x, y) => new
                                     {
                                         FeeDetail = y.DefaultIfEmpty()
                                     })
            .Select(x => x.FeeDetail)
            .SingleOrDefault();

        Assert.IsNotNull(recommendedFees);

       //order fees by lowest fee - *the bit I am stuck on*
        var bestMatch = recommendedFees.OrderBy(x => x.Lower)
            .TakeWhile(x => propValue >= x.Lower || propValue <= x.Upper)
            .FirstOrDefault();



    }
Run Code Online (Sandbox Code Playgroud)

问题 - 如何进行范围检查?我需要什么样的linq运算符?不确定我是否应该执行一段时间,从该范围获得最佳费用?

注意:费用很容易......

(费用较低 - 费用较高)

0 - 50000
50001 - 75000
95001 - 140000
190000 - 500000
Run Code Online (Sandbox Code Playgroud)

如果找到最佳匹配,请将其拉出获得最接近的匹配...也许我可以显示可用匹配列表,如果一个不匹配(足够接近)完全匹配

Ric*_*ton 5

只是一个简单的.Where应该是好的:

var bestMatch = recommendedFees
              .Where(x => propValue >= x.Lower && propValue <= x.Upper)
              .OrderBy(x => x.Lower)                  
              .FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)