LINQ用于累积记录

时间:2012-04-02 02:28:54

标签: c# linq entity-framework ado.net visual-studio-lightswitch

我有两个名为PatientsTelephoneCallsHistory的实体, 1-m 关系。

查询如下, enter image description here

数据模型是

enter image description here

以下是电话数据示例 enter image description here

我想返回患者记录,其中联系结果是回拨是必需的,在接下来的几条记录中提供没有联系目的已完成。基本上我正在尝试为用户创建警报/通知以进行跟进。

我提出了以下代码

query = query
     .Where(m => !m.PatientsMasterItem
             .PatientsTelephoneFollowupDetail.Any(l => l.Status == "1"));  

但它在上面给出的例子中不起作用(参考测试数据)。但最后的记录还需要采取行动才能跟进。

2 个答案:

答案 0 :(得分:1)

这不是编译的 - 这只是一个提示。你需要类似

之类的东西
        var required = query.Where(DoesPatientNeedCallback);

        public static bool DoesPatientNeedCallback(Patient p)
        {
              var last = p.PatientsMasterItem.PatientsTelephoneFollowupDetail.LastOrDefault(c => c.Status == 'Contact Required' || c.Status == 'Contact Purpose Completed);
              return last != null && last.Status == 'Contact Required'

        }

答案 1 :(得分:0)

完整的代码在

下面
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.LightSwitch;
using Microsoft.LightSwitch.Security.Server;

namespace LightSwitchApplication
{
public partial class ApplicationDataService
{

    partial void StatusCallBackRequired_PreprocessQuery(ref IQueryable<PatientsTelephoneFollowupDetail> query)
    {
        var required = query.Where(PatientNeedCallback);

    }

    public static bool PatientNeedCallback(PatientsTelephoneFollowupDetail p)
    {
        var last = p.PatientsMasterItem.PatientsTelephoneFollowupDetail.LastOrDefault(c => c.Status == "7" || c.Status == "1");
        return last != null && last.Status == "7";

    }
}    


}