I have a ServerDTO and associated RamInfoDTO and DriveInfoDTO as
[Serializable]
public class ServerDTO
{
[Key]
[Editable(false)]
public virtual string Id { get; set; }
public virtual string Name { get; set; }
public virtual string OS { get; set; }
public virtual string ProcInfo { get; set; }
[Include]
[Association("Server_RamInfos", "Id", "HostId")]
public IEnumerable<RamInfoDTO> RamInfo { get; set; }
[Include]
[Association("Server_DriveInfos", "Id", "HostId")]
public IEnumerable<DriveInfoDTO> DriveInfo { get; set; }
[Serializable]
public class DriveInfoDTO
{
[Key]
[Editable(false)]
public virtual string Drive { get; set; }
public virtual string Volume { get; set; }
public virtual double TotalSpace { get; set; }
public virtual double FreeSpace { get; set; }
public virtual string HostId { get; set; }
}
[Serializable]
public class RamInfoDTO
{
[Key]
public virtual string Name { get; set; }
public virtual double Amount { get; set; }
public virtual string HostId { get; set; }
}
I'm returning them as this:
public IEnumerable<ServerDTO> GetServerInfoDTO()
{
var lstServerInfoDTOs = _context.ServerInfos.Include("DriveInfos").OrderBy(s => s.Name).AsEnumerable()
.Select(s => new ServerDTO
{
Id = s.Id.ToString(),
Name = s.Name,
OS = s.OS,
ProcInfo = s.ProcessorInfo,
RamInfo = new List<RamInfoDTO>(){
new RamInfoDTO{HostId= s.Id.ToString(), Name="Total", Amount=ConvertSpaceToDouble(s.TotalRAM)},
new RamInfoDTO{HostId= s.Id.ToString(), Name="Free", Amount=ConvertSpaceToDouble(s.FreeRAM)}
},
DriveInfo = s.DriveInfos.AsEnumerable()
.Select(d => new DriveInfoDTO
{
HostId = s.Id.ToString(),
Drive = d.Drive,
Volume = d.Volume,
TotalSpace = ConvertSpaceToDouble(d.TotalSpace),
FreeSpace = ConvertSpaceToDouble(d.FreeSpace)
}).ToList()
}).ToList();
DumpDTO(lstServerInfoDTOs);
return lstServerInfoDTOs;
}
On the Client it gets bound to a DataForm in ReadOnly mode. The weird thing is that on the Server, using Debug.Writes I can see that the List returned has all entries but on the Client it shows with first DriveInfo entry fully populated and others as empty.
Hi. The problem is some of the properties which are marked with the "[Key]" attribute. Both the "Drive" property in DriveInfoDTO and the "Name" property in RamInfoDTO are not unique across the total number of objects; it's not enough to make them unique
in their current parent-child-context.
When you take a closer look at what arrives at the client you'll see that every entry with a certain key only appears once (the first time). That's why e.g. the second entry has a "D" drive (because the first one had no "D").
You need to use some real Ids to identify these objects, like the primary key of DriveInfos for the DriveInfoDTOs, and maybe a randomly generated Guid for the RamInfoDTOs.
Thanks that was it. Dumb of me not to spot that. I have an issue with BarChart Series showing up but also throwing the error window. I defined the chart like this:
It shows up, but then I get the error window with message
"Attempt by method
System.Windows.Control.ValidationUtil.GetDependencyPropertiesFieldorElement(System.Windows.FrameworkElement) to access field 'System.Windows.Controls.DataVisualization.LayoutTransforControl.ContentProperty' failed.
Hi Sunit. I don't see anything obvious. But I'm not exactly a chart expert. Maybe you should post a new topic for this question so others can take notice of it too.
sunitjoshi
Member
2 Points
12 Posts
Associations not working totally
Sep 22, 2010 07:48 PM | LINK
I have a ServerDTO and associated RamInfoDTO and DriveInfoDTO as
[Serializable] public class ServerDTO { [Key] [Editable(false)] public virtual string Id { get; set; } public virtual string Name { get; set; } public virtual string OS { get; set; } public virtual string ProcInfo { get; set; } [Include] [Association("Server_RamInfos", "Id", "HostId")] public IEnumerable<RamInfoDTO> RamInfo { get; set; } [Include] [Association("Server_DriveInfos", "Id", "HostId")] public IEnumerable<DriveInfoDTO> DriveInfo { get; set; } [Serializable] public class DriveInfoDTO { [Key] [Editable(false)] public virtual string Drive { get; set; } public virtual string Volume { get; set; } public virtual double TotalSpace { get; set; } public virtual double FreeSpace { get; set; } public virtual string HostId { get; set; } } [Serializable] public class RamInfoDTO { [Key] public virtual string Name { get; set; } public virtual double Amount { get; set; } public virtual string HostId { get; set; } }I'm returning them as this:
public IEnumerable<ServerDTO> GetServerInfoDTO() { var lstServerInfoDTOs = _context.ServerInfos.Include("DriveInfos").OrderBy(s => s.Name).AsEnumerable() .Select(s => new ServerDTO { Id = s.Id.ToString(), Name = s.Name, OS = s.OS, ProcInfo = s.ProcessorInfo, RamInfo = new List<RamInfoDTO>(){ new RamInfoDTO{HostId= s.Id.ToString(), Name="Total", Amount=ConvertSpaceToDouble(s.TotalRAM)}, new RamInfoDTO{HostId= s.Id.ToString(), Name="Free", Amount=ConvertSpaceToDouble(s.FreeRAM)} }, DriveInfo = s.DriveInfos.AsEnumerable() .Select(d => new DriveInfoDTO { HostId = s.Id.ToString(), Drive = d.Drive, Volume = d.Volume, TotalSpace = ConvertSpaceToDouble(d.TotalSpace), FreeSpace = ConvertSpaceToDouble(d.FreeSpace) }).ToList() }).ToList(); DumpDTO(lstServerInfoDTOs); return lstServerInfoDTOs; }On the Client it gets bound to a DataForm in ReadOnly mode. The weird thing is that on the Server, using Debug.Writes I can see that the List returned has all entries but on the Client it shows with first DriveInfo entry fully populated and others as empty.
Any thought what's happening here ??
riaservices silverlight4
MisterGoodcat
All-Star
32099 Points
4704 Posts
Re: Associations not working totally
Sep 23, 2010 06:53 AM | LINK
Hi. The problem is some of the properties which are marked with the "[Key]" attribute. Both the "Drive" property in DriveInfoDTO and the "Name" property in RamInfoDTO are not unique across the total number of objects; it's not enough to make them unique in their current parent-child-context.
When you take a closer look at what arrives at the client you'll see that every entry with a certain key only appears once (the first time). That's why e.g. the second entry has a "D" drive (because the first one had no "D").
You need to use some real Ids to identify these objects, like the primary key of DriveInfos for the DriveInfoDTOs, and maybe a randomly generated Guid for the RamInfoDTOs.
Goodcat Trainings
My Blog
Twitter
sunitjoshi
Member
2 Points
12 Posts
Re: Associations not working totally
Sep 23, 2010 01:11 PM | LINK
Thanks that was it. Dumb of me not to spot that. I have an issue with BarChart Series showing up but also throwing the error window. I defined the chart like this:
<toolkit:DataField Label="Drive Info" LabelPosition="Left"> <toolkit:Chart Name="chartDrives" LegendTitle="Space(GB)"> <toolkit:Chart.Series> <toolkit:BarSeries ItemsSource="{Binding DriveInfo}" DependentValuePath="TotalSpace" Title="Total" IndependentValuePath="Drive" /> <toolkit:BarSeries ItemsSource="{Binding DriveInfo}" Title="Free" DependentValuePath="FreeSpace" IndependentValuePath="Drive" /> </toolkit:Chart.Series> </toolkit:Chart> </toolkit:DataField>It shows up, but then I get the error window with message
"Attempt by method
System.Windows.Control.ValidationUtil.GetDependencyPropertiesFieldorElement(System.Windows.FrameworkElement) to access field 'System.Windows.Controls.DataVisualization.LayoutTransforControl.ContentProperty' failed.
Any idea?
thanks a lot.
Sunit
MisterGoodcat
All-Star
32099 Points
4704 Posts
Re: Associations not working totally
Sep 23, 2010 03:20 PM | LINK
Hi Sunit. I don't see anything obvious. But I'm not exactly a chart expert. Maybe you should post a new topic for this question so others can take notice of it too.
Goodcat Trainings
My Blog
Twitter
sunitjoshi
Member
2 Points
12 Posts
Re: Re: Associations not working totally
Sep 23, 2010 11:03 PM | LINK
Thanks...just found out that this is known "bug" for the chart control - unable to show within a DataField template.