views:

76

answers:

1

Hi. I have an ASP.NET MVC application in which i am using entity model for connecting to MySQl database

Here I am joining 2 tables and then applying group by on one of the fields. Then fetching the result from GroupBy result. Everything is working fine on development machine but getting next error:

Object Must Implement IConvertible

Can you please help me out why such error is occurring. I have taken the dump of database form staging server and then used that on development machine then also working fine. But when I placed the dump of development machine database on staging then getting the same exception.

So where is problem i am not understanding.

The model structure is

student:
studentid int 
course string
name string

student_payment:
id int 
studentid int 
amount decimal

Here student and student_payment has association on studentid of one to many.

Query:

var query = from s in entity.student_payment.Include("student")
            group s by s.registrant.course into grp 
            select new 
            { 
                course = grp.Key, 
                count = (from studentcnt in grp select studentcnt.student.studentid), 
                payment = (from payment in grp select payment)
            };

foreach (var q in query) // exception is occurring here
{
    studentcount == q.count.Distinct().Count()
    iamount = payment.Sum(r => r.amount);
}

In the query i have applied the GroupBy on the course and then fetching the record from the associated tables.

A: 

hi..

I am able to solve the error .I think when we are having association between the tables then with group by we cannot apply select subqueries.

So I use the select query while parsing the result set of groupby.

var query = from s in entity.student_payment.Include("student") group s by s.registrant.course into grp select new { course = grp.Key,

        };

foreach (var q in query) // exception is occurring here { var count = (from studentcnt in entity.student_payment.Include("student") where student.course==q.course select studentcnt );

payment = (from payment in grp select payment)

studentcount == count.Select(r=>r.student.studentid).Distinct().Count()

iamount = count.Sum(r => r.amount); }