Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Problem in Converting object to json

$
0
0

Hi friends :)

when i use this query to return json,everything is ok!

            var Result2 = (from r in Result
                           join l in db.tbl_lessons
                           on r.idLesson2 equals l.idLesson
                           where r.idLesson2 == l.idLesson || r.idLesson2 == 0

                           join t in db.tbl_teachers
                           on r.idTeacher2 equals t.idTeacher
                           where r.idTeacher2 == t.idTeacher || r.idTeacher2 == 0
                           select new

                           {
                               r.End,
                               r.Start,
                               r.idBell,
                               r.idClass,
                               r.idDataTable,
                               r.idDay,
                               r.idLesson,
                               r.idLesson2,
                               r.idTeacher,
                               r.idTeacher2,
                               r.idYear,
                               r.isTak,
                               TakStatr = r.TakStatr,
                               TakEnd = r.TakEnd,
                               r.dayName,
                               r.BellName,
                               r.yearName,
                               LessonName = r.lessonName,
                               LessonName2 = l.lessonName,
                               r.teacheName,
                               t.FName,
                               t.LName,
                               r.className

                           }).ToList().Select(r => new
                           {
                               r.yearName,
                               r.className,
                               r.dayName,
                               r.BellName,
                               r.LessonName,
                               TeacheName = r.teacheName,
                               r.Start,
                               r.End,
                               r.isTak,
                               r.TakStatr,
                               r.TakEnd,
                               LessonName2 = r.LessonName2,
                               TeacheName2 = r.FName + " " + r.LName,
                               r.idBell,
                               r.idClass,
                               r.idDataTable,
                               r.idDay,
                               r.idLesson,
                               r.idLesson2,
                               r.idTeacher,
                               r.idTeacher2,
                               r.idYear,
                           }).ToList();

            var jsonSerialiser = new JavaScriptSerializer();
            var json = jsonSerialiser.Serialize(Result2);

            return new HttpResponseMessage()
            {
                Content = new StringContent(
                    json.ToString()

                )
            };

But use .Tolist() twice in query make it very lazy when the rows is more than 10000!

I tried to use .AsQueryable inested of .Tolist()!
but this time i get this error:
Unable to cast the type 'System.Int32' to type 'System.Object'. LINQ to Entities only supports casting EDM primitive or enumeration types.

Thanks for any Help :)


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>