I have an list of objects which each have a list of attributes. In the grid displaying the list of objects, I to show as the attributes as columns instead of showing them in a subgrid.
public class MyObject {
public int Id {get; set;}
public string Name {get; set;}
public IEnumerable<MyAttribute> Attributes {get; set;}
}
public class MyAttribute {
public int Id {get; set;}
public string Key {get; set;}
public string Value {get; set;}
}
So what I have is a IEnumerable<MyObject>
. e.g.
var lst = new[]
{
new MyObject
{
Id = 1,
Name = "o1",
Attributes = new[]
{
new MyAttribute
{
Id = 1,
Key = "k",
Value = "v1"
},
new MyAttribute
{
Id = 2,
Key = "x",
Value = "v2"
},
}
},
new MyObject
{
Id = 2,
Name = "o2",
Attributes = new[]
{
new MyAttribute
{
Id = 3,
Key = "k",
Value = "v11"
},
new MyAttribute
{
Id = 4,
Key = "x",
Value = "v22"
},
}
}
};
And the grid I would like to end up with would then have 4 columns, Id, Name, k, x.
I have 2 problems...
The component I use to display the grid, uses
ModelMetadataProviders.Current.GetMetadataForType((Func<object>) null, typeof (TModel))
to figure out which columns to show. How do I convince the ModelMetadataProviders to include these extra columns?Similar, the code to get the values
ModelMetadataProviders.Current.GetMetadataForProperties(this.Value, typeof (TModel))
, how do I convince it to send those extra values?
If I can find a solution for the 2nd problem, I can probably find a workaround for the first one, since that is just a helper class.