I checked similar questions such as:
How do I select a collection within a collection using LINQ?
How to return ICollection<object> from linq, when using select new object() {}
What I'm trying to do is return the list in Json format to be used in a Javascript GET request and display it on a cshtml page.
var query = (from c in db.photos
orderby c.date_created descending
select new { id = c.id, name = c.name, image_url = c.image_url, description = c.description, photos_has_characters = c.photos_has_characters.FirstOrDefault() })
.Skip(pageIndex * pageSize)
.Take(pageSize);
return Json(query.ToList(), JsonRequestBehavior.AllowGet);
However, when I go to the page nothing loads or shows an error I can pinpoint, so it has to be the photos_has_characters part in the LINQ.
How do I accomplish displaying those associated entities? Let me re-clarify. So I have a character's table and a photos tables with a many to many relationship table called photos_has_characters. I want to also select the character name and id from that photos_has_characters collection and return that information with the select new object. How do I do that?
If I'm missing something I will add it, thank you in advance.
EDIT:
In client-side on console I get this error:
What the LINQ is returning for photos_has_characters parameter... Although it doesn't return an error, the parameter for new object of the photos_has_characters collection returns this:
photos_has_characters = {System.Data.Entity.DynamicProxies.photos_has_character_A0E9952F88D75712B3DACC51D4EA09329C0427E5A9FED3F11F4EE0EC2AE1B579}
That into Json to be read using Javascript results in nothing. How do I modify my LINQ to accomodate?