Hi Sophie, (I tried to e-mail you but i am in france at the moment ad can't send for some reason.), sorry I don’t as MS have not adding the insert and update parameters to the DomainServiceDataSource, I may have a way of getting it to work but not had the
time to try it out.
Just in case you want to try yourself I was thinking of adding on inserting and on updating event to the child grid see the EF ManyToMany_Edit field template for how to do that and then add the parameters there J
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
Hi there, I have found a generic way of doing this though so far only for Viewing - I have not tried updating the gridview yet.
This is how I managed to get it to work.
public partial class ChildGrid : FieldTemplateUserControl
{
protected MetaTable DisplayTable { get; set; }
private String[] DisplayColumns { get; set; }
private String DisplayTableName { get; set; }
protected void Page_Init(object sender, EventArgs e)
{
var attribute = Column.Attributes.OfType<ShowChildColumnsAttribute>().SingleOrDefault();
if (attribute != null)
{
if (attribute.DisplayColumns.Length > 0)
DisplayColumns = attribute.DisplayColumns;
DisplayTableName = attribute.TableName;
}
DisplayTable = Column.Table.Model.GetTable(DisplayTableName);
GridView1.ColumnsGenerator = new FieldTemplateRowGenerator(DisplayTable, DisplayColumns);
// setup the GridViewDataKeys
var keys = new String[DisplayTable.PrimaryKeyColumns.Count];
int i = 0;
foreach (var keyColumn in DisplayTable.PrimaryKeyColumns)
{
keys[i] = keyColumn.Name;
i++;
}
GridView1.DataKeyNames = keys;
GridView1.SetMetaTable(DisplayTable);
}
protected override void OnDataBinding(EventArgs e)
{
// Get the real entity from the wrapper
object entity = Row;
// Get the collection of reservations for this customer and make sure it's loaded
var entityCollection = (RelatedEnd) Column.EntityTypeProperty.GetValue(entity, null);
entityCollection.Load();
var objectQuery = (ObjectQuery) entityCollection.GetType().GetMethod(
"CreateSourceQuery").Invoke(entityCollection, null);
GridView1.DataSource = objectQuery;
}
// use this to navigate to the Details page for our Child Grid
// gets the primary keys from the grid datakeys and uses these to
// navigate to the details page for the table in question
protected void GridSelectedIndexChanged(object sender, EventArgs e)
{
// Get the currently selected row using the SelectedRow property.
string primarykeyvalues = string.Empty;
// now let's build up the primary keys for the redirect
if (GridView1.SelectedDataKey != null)
{
var keys = GridView1.SelectedDataKey.Values;
foreach (DictionaryEntry key in keys)
{
primarykeyvalues = primarykeyvalues + key.Key;
primarykeyvalues = primarykeyvalues + "=" + key.Value + "&";
}
primarykeyvalues = primarykeyvalues.TrimEnd('&', ' ');
}
Response.Redirect("../" + DisplayTable + "/DetailsSubGridViews.aspx?" + primarykeyvalues);
}
None
0 Points
2 Posts
MetaChildrenColumn not created when using a DomainService with a one to Many Mapping
Sep 20, 2013 06:32 AM|sdemalet|LINK
I am using the Entity Framework and a Domain Service and I have a one-to-many mapping between two tables
I am trying to use the Dynamic Child grid example by Steve Naughton but My Data column is an EntityCollection rathen than a MetaChildrenColumn.
Has anyone got an equivalent solution
If I just try and use the EntityCollection then it is strongly typed to the actual child entity and I am looking for a more generic solution.
Has anyone come across this and found an equivalent solution?
Thanks
All-Star
17916 Points
5681 Posts
MVP
Re: MetaChildrenColumn not created when using a DomainService with a one to Many Mapping
Sep 21, 2013 03:09 PM|sjnaughton|LINK
Hi Sophie, (I tried to e-mail you but i am in france at the moment ad can't send for some reason.), sorry I don’t as MS have not adding the insert and update parameters to the DomainServiceDataSource, I may have a way of getting it to work but not had the time to try it out.
Just in case you want to try yourself I was thinking of adding on inserting and on updating event to the child grid see the EF ManyToMany_Edit field template for how to do that and then add the parameters there J
Always seeking an elegant solution.
None
0 Points
2 Posts
Re: MetaChildrenColumn not created when using a DomainService with a one to Many Mapping
Sep 26, 2013 11:10 AM|sdemalet|LINK
Hi there, I have found a generic way of doing this though so far only for Viewing - I have not tried updating the gridview yet.
This is how I managed to get it to work.
This seems to work quite nicely so far...