Dec 18, 2009, 5:03 AM
Bind objects from LINQ to DataView
Hi there!
I wanna use a DataView with a template like in XTemplate Examples to display nested data.
How do I get my nested data from LINQ?
I bound my DataView to an ObjectDatasource which is read into a store by a JSON reader. The <tpl for="."> is displayed as wanted. But I can't get the nested children to work.
My code to fill the ObjectDatasource is this:
I wanna use a DataView with a template like in XTemplate Examples to display nested data.
<tpl for=".">
<p>
Father: {Name}
</p>
<p>
Children:
<tpl for="Children">
{Name}<br />
</tpl>
</p>
<hr />
</tpl>
In the example the DataView is bound to an ObjectHolder. Nesting of data works fine there.How do I get my nested data from LINQ?
I bound my DataView to an ObjectDatasource which is read into a store by a JSON reader. The <tpl for="."> is displayed as wanted. But I can't get the nested children to work.
My code to fill the ObjectDatasource is this:
public static List<FATHER> GetFathers(string id)
{
if (!string.IsNullOrEmpty(id))
{
DataContext db = new DataContext();
IQueryable<FATHER> fathers = db.FATHER
.Select(f => f)
.Where(f => f.id.Equals(id));
// Up to here it works fine
foreach (FATHER father in fathers)
{
IQueryable<CHILD> children = db.CHILD
.Select(c => c)
.Where(c => c.FATHER_ID.Equals(FATHER.id));
father.children = children;
}
// The foreach doesn't do what I want. Maybe the JSON.Serialize() fails?
return fathers.ToList();
}
else
{
return null;
}
}
I also extended the FATHER LINQ-to-SQL class like this to get the children property:partial class FATHER
{
public List<CHILD> children { get; set; }
}
Hope somebody gets the point and can help me :)