Domanda

So I am not very strong in LINQ and Databases in general, so please understand i know i am a novice. I am trying to get information from a system about employees activity. Here is the issue, I have 4 mysql queries that return tables to me. I get the information like so

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

I then get other results and try to use Linq to join them:

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

but all i get is this error Could not find an implementation of the query pattern for source type 'System.Data.EnumerableRowCollection'. 'Join' not found. Are you missing a reference or a using directive for 'System.Linq'?

edited:

I cannot get myLinq to bind properly as a DataTable due to the anonymous datatype any idea what i am doing wrong?

È stato utile?

Soluzione

Try adding a reference to System.Core and a using directive for System.Linq and System.Data.Linq

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top