不支持“Equals”方法

时间:2011-03-23 10:28:42

标签: subsonic

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 ??

制作相同的方法

1 个答案:

答案 0 :(得分:0)

你试过这个:

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

其他信息:

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

一个很好的起点,可以知道TSqlFormatter类支持什么和不支持什么。看看protected override Expression VisitMethodCall(MethodCallExpression m)

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

已经有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;
            }
        }

我认为Prnsioners是一个整数类型,所以你基本上必须添加另一个if if和recomplie subsonic。

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

            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;
            }

(或者您可以尝试==方法,就像在顶部的示例中一样。)