错误代码 - 非静态方法需要目标

本文关键字:目标 静态方法 错误代码 | 更新日期: 2023-09-27 18:36:44

我的问题是执行此代码时出错。此功能可以完美地应用于其他用途。

这是我的完整函数代码:

public List<t_heure_indemnite> GetAllHeureIndemnite(FirmMda f, bool justeActive)
{
    List<t_heure_indemnite> lHi = new List<t_heure_indemnite>();
    ce = new callistoEntities();
    try
    {
       var load = from i in ce.t_heure_indemnite
                  where i.FIRM == f.Name
                  select i;
       if (load != null)
       {
           List<t_heure_indemnite> liste = load.ToList();
           foreach (t_heure_indemnite h in liste)
           {
               lHi.Add(h);
           }
       }
   }
   catch (Exception e)
   {
       MsgBox.Show(globale.AfficheErreur(e));
   }
   if (justeActive)
       return lHi.Where(i => i.ACTIVE == true).OrderBy(j => j.ORE).ToList();
   else
       return lHi.OrderBy(j => j.ORDRE).ToList();
}

执行时出现异常:非静态方法需要目标。加载时出现。调用 ToList。它被调用到公共方法中,并在将 traiteation 导入到其他列表中。

我不知道问题出在哪里。你能帮我吗?

错误代码 - 非静态方法需要目标

当您在 lambda 表达式中使用空引用变量时,可能会发生这种情况。 我建议检查您的变量ce.t_heure_indemnite是否为空引用。

if(ce.t_heure_indemnite != null)