“等于”方法不支持

发布于 2024-10-26 17:19:47 字数 2203 浏览 1 评论 0原文

public List<Health_Scheme_System.Employee> GetPenEmployeeTable()
{   
    Health_Scheme_System.Health_Scheme_SystemDB db = new Health_Scheme_System.Health_Scheme_SystemDB();

    var x = (from c in db.Employees
             where c.Pensioners.Equals (1) 
             select c); 

    return x.ToList();
}   

//Selecting multiple columns from an HR view table together with the scheme name of scheme.
public List<EmployeesX> GetPensioners()
{   
    Health_Scheme_System.Health_Scheme_SystemDB db = new Health_Scheme_System.Health_Scheme_SystemDB();

    List<Health_Scheme_System.EmployeeDirectory> listEmployeeView = GetPenEmployeeView();
    List<Health_Scheme_System.Employee> listEmployeeTable = GetPenEmployeeTable();
    List<Health_Scheme_System.Scheme> listSchemes = GetSchemes();

    List<EmployeesX> listOfEmployees = new List<EmployeesX>();

    //checking for comparision of getemployeeview to getemployee table and then to getschemes
    //Then display the scheme name if they are similar.
    for (int i = 0; i < listEmployeeView.Count; i++)
    {   
        EmployeesX emp = new EmployeesX();
        emp.ID_NO = listEmployeeView[i].ID_NO;
        emp.FIRST_NAME = listEmployeeView[i].FIRST_NAME;
        emp.LAST_NAME = listEmployeeView[i].LAST_NAME;
        emp.LOCATION_CODE = listEmployeeView[i].LOCATION_CODE;

        for (int j = 0; j < listEmployeeTable.Count; j++)
        {   
            if (listEmployeeTable[j].EmployeeIDCard == listEmployeeView[i].ID_NO)
            {   
                emp.Pensioners = listEmployeeTable[j].Pensioners;

                    for (int k = 0; k < listSchemes.Count; k++)
                    {   
                        if (listEmployeeTable[j].SchemeID == listSchemes[k].SchemeID)
                        {   
                            emp.SCHEME_NAME = listSchemes[k].Name;
                            emp.START_DATE = listEmployeeTable[j].StartSchemeDate;
                        }   
                    }   
            }   
        }   
        listOfEmployees.Add(emp);
    }   
    return listOfEmployees;
}   

如何使用 .equals 做出相同的方法?

public List<Health_Scheme_System.Employee> GetPenEmployeeTable()
{   
    Health_Scheme_System.Health_Scheme_SystemDB db = new Health_Scheme_System.Health_Scheme_SystemDB();

    var x = (from c in db.Employees
             where c.Pensioners.Equals (1) 
             select c); 

    return x.ToList();
}   

//Selecting multiple columns from an HR view table together with the scheme name of scheme.
public List<EmployeesX> GetPensioners()
{   
    Health_Scheme_System.Health_Scheme_SystemDB db = new Health_Scheme_System.Health_Scheme_SystemDB();

    List<Health_Scheme_System.EmployeeDirectory> listEmployeeView = GetPenEmployeeView();
    List<Health_Scheme_System.Employee> listEmployeeTable = GetPenEmployeeTable();
    List<Health_Scheme_System.Scheme> listSchemes = GetSchemes();

    List<EmployeesX> listOfEmployees = new List<EmployeesX>();

    //checking for comparision of getemployeeview to getemployee table and then to getschemes
    //Then display the scheme name if they are similar.
    for (int i = 0; i < listEmployeeView.Count; i++)
    {   
        EmployeesX emp = new EmployeesX();
        emp.ID_NO = listEmployeeView[i].ID_NO;
        emp.FIRST_NAME = listEmployeeView[i].FIRST_NAME;
        emp.LAST_NAME = listEmployeeView[i].LAST_NAME;
        emp.LOCATION_CODE = listEmployeeView[i].LOCATION_CODE;

        for (int j = 0; j < listEmployeeTable.Count; j++)
        {   
            if (listEmployeeTable[j].EmployeeIDCard == listEmployeeView[i].ID_NO)
            {   
                emp.Pensioners = listEmployeeTable[j].Pensioners;

                    for (int k = 0; k < listSchemes.Count; k++)
                    {   
                        if (listEmployeeTable[j].SchemeID == listSchemes[k].SchemeID)
                        {   
                            emp.SCHEME_NAME = listSchemes[k].Name;
                            emp.START_DATE = listEmployeeTable[j].StartSchemeDate;
                        }   
                    }   
            }   
        }   
        listOfEmployees.Add(emp);
    }   
    return listOfEmployees;
}   

How can I make the same method with using .equals??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北风几吹夏 2024-11-02 17:19:47

您是否尝试过此操作:

var x = (from c in db.Employees
         where c.Pensioners == 1
         select c)

附加信息:

如果您在 linq 查询中的对象上使用方法,亚音速需要知道如何将其转换为 pur SQL 代码。默认情况下这不起作用,并且必须为每个数据提供程序的每个受支持类型上的每个已知方法实现(如果与默认实现不同)。因此,亚音速还有很多工作要做。

了解支持什么和不支持什么的一个很好的起点是 TSqlFormatter 类。看看protected override Expression VisitMethodCall(MethodCallExpression m)

https://github.com/subsonic/SubSonic-3.0/blob/master/SubSonic.Core/Linq/Structure/TSqlFormatter.cs

已经有一个 Equals< 的实现/code>

        else if (m.Method.Name == "Equals")
        {
            if (m.Method.IsStatic && m.Method.DeclaringType == typeof(object))
            {
                sb.Append("(");
                this.Visit(m.Arguments[0]);
                sb.Append(" = ");
                this.Visit(m.Arguments[1]);
                sb.Append(")");
                return m;
            }
            else if (!m.Method.IsStatic && m.Arguments.Count == 1 && m.Arguments[0].Type == m.Object.Type)
            {
                sb.Append("(");
                this.Visit(m.Object);
                sb.Append(" = ");
                this.Visit(m.Arguments[0]);
                sb.Append(")");
                return m;
            }
            else if (m.Method.IsStatic && m.Method.DeclaringType == typeof(string))
            {
                //Note: Not sure if this is best solution for fixing side issue with Issue #66
                sb.Append("(");
                this.Visit(m.Arguments[0]);
                sb.Append(" = ");
                this.Visit(m.Arguments[1]);
                sb.Append(")");
                return m;
            }
        }

我想 Prnsioners 是一个整数类型,所以你基本上必须添加另一个 else if 并重新编译亚音速。

这应该有效,但我还没有测试过。

            else if (!m.Method.IsStatic && m.Method.DeclaringType == typeof(int))
            {
                sb.Append("(");
                this.Visit(m.Arguments[0]);
                sb.Append(" = ");
                this.Visit(m.Arguments[1]);
                sb.Append(")");
                return m;
            }

(或者您可以尝试使用 == 方法,如顶部的示例所示)。

Have you tried this:

var x = (from c in db.Employees
         where c.Pensioners == 1
         select c)

Additional info:

If you use a method on an object in a linq query subsonic needs to know how to translate that into pur SQL code. That does not work by default and must be implemented for every known method on every supported type for every dataprovider (if differs from default implementation). So there is a bunch of work to do for subsonic.

A good starting point for knowning what's supported and what not is the TSqlFormatter class. Have a look at protected override Expression VisitMethodCall(MethodCallExpression m)

https://github.com/subsonic/SubSonic-3.0/blob/master/SubSonic.Core/Linq/Structure/TSqlFormatter.cs

There is already an implementation for Equals

        else if (m.Method.Name == "Equals")
        {
            if (m.Method.IsStatic && m.Method.DeclaringType == typeof(object))
            {
                sb.Append("(");
                this.Visit(m.Arguments[0]);
                sb.Append(" = ");
                this.Visit(m.Arguments[1]);
                sb.Append(")");
                return m;
            }
            else if (!m.Method.IsStatic && m.Arguments.Count == 1 && m.Arguments[0].Type == m.Object.Type)
            {
                sb.Append("(");
                this.Visit(m.Object);
                sb.Append(" = ");
                this.Visit(m.Arguments[0]);
                sb.Append(")");
                return m;
            }
            else if (m.Method.IsStatic && m.Method.DeclaringType == typeof(string))
            {
                //Note: Not sure if this is best solution for fixing side issue with Issue #66
                sb.Append("(");
                this.Visit(m.Arguments[0]);
                sb.Append(" = ");
                this.Visit(m.Arguments[1]);
                sb.Append(")");
                return m;
            }
        }

I suppose Prnsioners is an integer type so you basically have to add another else if and recomplie subsonic.

This should work but I haven't tested it.

            else if (!m.Method.IsStatic && m.Method.DeclaringType == typeof(int))
            {
                sb.Append("(");
                this.Visit(m.Arguments[0]);
                sb.Append(" = ");
                this.Visit(m.Arguments[1]);
                sb.Append(")");
                return m;
            }

(or you can try the == approach like in the example on the top).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文