0

所以我一般在 LINQ 和数据库方面不是很强,所以请理解我知道我是新手。我正在尝试从系统中获取有关员工活动的信息。这是问题所在,我有 4 个 mysql 查询将表返回给我。我得到这样的信息

private DataTable GetBreaks()
    {
        server = "someip";
        database = "calls";
        uid = "user";
        password = "password";
        int port = 999999;
        string connectionString;
        connectionString = "server=" + server + ";" + "database=" + database + ";" + "port=3306;" + "user=" + uid + ";" + "password=" + password + ";";

        connection = new MySqlConnection(connectionString);

        if (this.OpenConnection() == true)
        {
            DataSet dt = new DataSet();
            DateTime endDateRun = radDateTimePicker2.Value.Date;
            DateTime endDate;
            DateTime startDate = radDateTimePicker1.Value.Date;
            if (endDateRun != startDate)
            {

                do
                {
                    endDate = startDate.AddDays(1);
                    string start = startDate.ToString("yyyy-MM-dd HH:mm:ss");
                    string end = endDate.ToString("yyyy-MM-dd HH:mm:ss");
                    string standard = "SELECT number, agent, break, (SUM(TIME_TO_SEC(duration))) AS Total FROM agentBreaks WHERE (datetime_init > '+ start +' and datetime_init < '+ end+' ) and (break= '15 Minute') GROUP BY break,agent

" + "join break on (audit.id_break = break.id) where (datetime_init >'" + start + "' and datetime_init < '" + end + "') and (break.name = '15 Minute') GROUP BY break.name,agent"; mySqlDataAdapter = new MySqlDataAdapter(standard, connection); DataSet DS = new DataSet(); mySqlDataAdapter.Fill(DS);

                    DS.Tables[0].Columns.Add(new DataColumn("date"));
                    for (int i = 0; i <= DS.Tables[0].Rows.Count - 1; i++)
                    {
                        DS.Tables[0].Rows[i]["date"] = startDate.ToString();
                    }
                    dt.Merge(DS);
                    startDate = startDate.AddDays(1);
                } while (endDateRun != endDate);

            }
            //close connection
            this.CloseConnection();
            return dt.Tables[0];
        }
        return null;
    }

然后我得到其他结果并尝试使用 Linq 加入它们:

 protected void CreateUnifiedTable()
    {
        DataTable Merged;
        DataTable dt1 = GetClockin();
        DataTable dt2 = GetLunch();
        DataTable dt3 = GetBreaks();
        DataTable dt4 = GetOther();
        var myLINQ = from DataTable t1 in dt1.AsEnumerable()
                     join t2 in dt2.AsEnumerable() on new { t1.id_agent, t1.date } equals new { t2.id_agent, t2.Columnsdate }
                     join t3 in dt3.AsEnumerable() on new { t1.id_agent, t1.date } equals new { t3.id_agent, t3.Columnsdate }
                     join t4 in dt4.AsEnumerable() on new { t1.id_agent, t1.date } equals new { t4.id_agent, t4.Columnsdate }


                     select new
                     {
                         name = t1.Field<string>("agent"),
                         login = t1.Field<DateTime>("Login"),
                         fifteenMinute = t3.Field<TimeSpan>("Total"),
                         lunch = t2.Field<TimeSpan>("Total"),
                         other = t4.Field<TimeSpan>("Total"),
                         logout = t1.Field<TimeSpan>("Logout"),
                         total = t1.Field<TimeSpan>("Total") - t2.Field<TimeSpan> "Total")
                     };
    }

但我得到的只是这个错误找不到源类型'System.Data.EnumerableRowCollection'的查询模式的实现。未找到“加入”。您是否缺少“System.Linq”的引用或使用指令?

编辑:

由于匿名数据类型,我无法让 myLinq 正确绑定为 DataTable 知道我在做什么错吗?

4

1 回答 1

1

尝试添加对 System.Core 的引用以及 System.Linq 和 System.Data.Linq 的 using 指令

于 2013-08-02T16:16:43.957 回答