score:1
Accepted answer
There is probably a better way, but Nix's answer helped me come up with this:
var data = from a in attributes
select new
{
Id = a.Id,
LabelText = a.LabelText,
Items = attributeItems.Where(x=>x.DocClassAttributeFieldId == a.Id)
};
JavaScriptSerializer serializer = new JavaScriptSerializer();
TextBox1.Text = serializer.Serialize(data);
score:2
You can do it but you need to use a group into to populate items.
var data =
from a in attributes
from i in attributeItems.Where(x=>x.DocClassAttributeFieldId == a.Id )
group a by a.Id, a.LabelText into myGroup
.DefaultIfEmpty(new DocClassAttributeFieldItem())
select new
{
Id = a.Id,
LabelText = a.LabelText,
Items = myGroup.ToList()
};
JavaScriptSerializer serializer = new JavaScriptSerializer();
TextBox1.Text = serializer.Serialize(data);
That was a shot from the hip, so let me know if it doesn't work for you.
Source: stackoverflow.com
Related Query
- Can I get JavaScriptSerializer to serialize a LINQ result hierarchically?
- Can I use a LINQ IEnumerable result as the data source for a Gtk.TreeView?
- Can I assign the result of a Linq query to the source variable of the same query?
- How can get a result of a linq stored procedure into a label which is scalar
- Can not get the expected result in many to many relationship using LINQ in Asp.net C#, MVC, Codefirst application
- How can add Query LINQ to get result from table?
- How can I get LINQ to return the object which has the max value for a given property?
- Where can I get a good, concise LINQ cheatsheet?
- Where can I view LINQ source code?
- How to get linq result as string array?
- How can I get LINQ to return the index of the object which has the max value in a collection?
- how to get all columns from a linq result with a join
- LINQ Source Code Available
- How can I switch that code to use LINQ
- How can I combine this code into one or two LINQ queries?
- How can i get a string from linq expression?
- Can LINQ be used in Dynamics CRM to get all Accounts not in a Collection?
- How can I write the following code more elegantly using LINQ query syntax?
- How can I further simplify this piece of LINQ code
- Does the C# LINQ Aggregate method finish execution once the result can no longer change?
- How can I code an outer join using LINQ and EF6?
- How I can pass the LINQ result anonymous type to another method?
- How can I get the highest number in this Linq result?
- Can Linq `Where` clause query result be different depending on whether query is executed lazily or non-lazily?
- How to get Multiple Result Set in Entity Framework using Linq with C#?
- Can I use LINQ to get more than 100 records back from a Quickbooks Online ServiceContext?
- Get result function in LINQ without translate to store expression
- Retrieve bool result by using LinQ code
- How to get SQL query into LINQ form in C# code
- How can I code a Linq query to do an upward Include?
More Query from same tag
- using a look up table to query a many to many relationship and return all that meet the criteria
- How to order a list
- Combinations from different groups in a specific order
- How to left outer join for two unequal lists in linq
- ServiceStack select projection not working as expected
- Linq query not returning anything
- Order by item from list inside list
- IEnumerable to List performance issue
- Assigning LINQ Results to child Property - InvalidCastException: Unable to cast object of type
- LINQ to XML query does not read my XML file
- Sum "Amount" from one table and display in Another Table
- Strange behavior with IEnumerable/IQueryable extension (no lazy loading?)
- C# Removing Duplicates from a List Containing a List
- Using Linq to Query a Service Reference
- Return multiple attributes of an element to a list. LINQ to XML
- Best way to check if value exists for a key in ILookup<string, string> using linq
- To call SelectMany dynamically in the way of System.Linq.Dynamic
- Having some trouble understanding Linq's INTO keyword
- Linq select records closest to date
- How to use whereif in LINQ
- How can I concatenate all the column values in a row, and then concatenate all rows in a DataTable into a single string?
- How to extend this LINQ List<>.Contains to work with any Property using Reflection?
- Linq over Stored Procedures
- Implement an SQL query in LINQ
- LINQ Linq2Sql Queryable SelectMany InvalidOperationException
- Exec Procedure who receive data from Entity Framework
- Find element with specific attribute in xml?
- How to provide entity type/dbset type in Generic Repository
- Simple query on linq
- Add simultaneity two object depend on each other