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 Articles
- Can I get JavaScriptSerializer to serialize a LINQ result hierarchically?
- LINQ Source Code Available
- Retrieve bool result by using LinQ code
- creating Linq to sqlite dbml from DbLinq source code
- Using LINQ query result for data source for GridControl c#
- SQL subquery result in LINQ and Entity Framework Code First
- LINQ deferred execution with a function's result as source (e.g. Console.ReadLine)
- Can I use a LINQ IEnumerable result as the data source for a Gtk.TreeView?
- Code practice to handle empty result set in Linq to custom list
- source code for LINQ 101 samples
- Issue while converting linq result to JSON in MVC4 using JavaScriptSerializer
- Why is linq result updated, if a source is updated afterwards?
- How to break link between source collection and LINQ result
- Can I assign the result of a Linq query to the source variable of the same query?
- c# Linq or code to extract groups from a single list of source data
- Reuse stored procedure result in linq to sql in Code First
- Convert Linq Query Result to Dictionary
- Convert string[] to int[] in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Filling a DataSet or a DataTable from a LINQ query result set
- Linq code to select one item
- Cast LINQ result to ObservableCollection
- How are people unit testing code that uses Linq to SQL
- If Linq Result Is Empty
- Join Subquery result in Linq
- How to convert LINQ query result to List?
- LINQ group by then order groups of result
- Select top 1 result from subquery in linq to sql
- Best practices for dealing with LINQ statements that result in empty sequences and the like?
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- Linq Sql Query Error for Get value
- ASP:ListBox Get Selected Items - One Liner?
- SQL Query to LINQ
- Creating associations in a dbml file?
- Forgiving/Fuzzy search with LINQ
- NHibernate LINQ query performance, which code fragment is better?
- Get value of each comma separated ID from another table in Web Api-not working in live
- Trim All Cells of a DataTable
- Best way to get range from 1 to n-1 with linq
- Get XML node value using .EndsWith
- Is there a difference between these two statements in Linq?
- Domain Logic vs. Linq-to-Entites and Expression Trees
- Wildcard search in LINQ to SQL query not executing
- Iterate through elements of the same name and return attribute by another attribute value
- how to retrieve data from helper class property using Linq query C#
- operation cannot be completed because the DbContext has been disposed."
- Using List in FindAll function -C# LinQ
- How to find the index of first occurrence of a specific type of character after some substring?
- Linq SQL query has more precision for doubles
- Unable to cast object of type 'System.Data.Entity.Infrastructure.DbQuery`