Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Associations not working totally RSS

4 replies

Last post Sep 23, 2010 11:03 PM by sunitjoshi

(0)
  • sunitjoshi

    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.

    On Server...
    Id: 956632f9-7af1-4bcf-bb01-d5179539660c Name: SP3DSMP1
    	 Total: 31.99
    	 Free: 6.7
    	 Name: E:, TotalSpace: 1830.53
    	 Name: C:, TotalSpace: 119.77
    	 Name: H:, TotalSpace: 465.76
    	 Name: F:, TotalSpace: 2094.25
    	 Name: G:, TotalSpace: 97.65
    Id: 7816e947-e6ed-4def-b430-515c4590e2fc Name: SP3DSMP2
    	 Total: 8
    	 Free: 4.08
    	 Name: C:, TotalSpace: 68.32
    	 Name: D:, TotalSpace: 136.73
    	 Name: G:, TotalSpace: 68.48
    	 Name: E:, TotalSpace: 34.1
    	 Name: F:, TotalSpace: 68.48
    Id: 96688538-af1a-437d-8547-2e03293e44aa Name: SP3DSMP3
    	 Total: 3.94
    	 Free: 1.16
    	 Name: E:, TotalSpace: 232.82
    	 Name: D:, TotalSpace: 203.5
    	 Name: C:, TotalSpace: 29.29
    Id: 2fbf9545-d657-48ae-a567-8e3cf7a1a3a4 Name: SP3DSMP4
    	 Total: 8
    	 Free: 2.57
    	 Name: E:, TotalSpace: 232.82
    	 Name: D:, TotalSpace: 170.02
    	 Name: C:, TotalSpace: 50.01
    	 Name: Z:, TotalSpace: 12.78
    	 Name: G:, TotalSpace: 279.46
    On Client...
    Id: 956632f9-7af1-4bcf-bb01-d5179539660c Name: SP3DSMP1
    	 Total: 31.99
    	 Free: 6.7
    	 Name: E:, TotalSpace: 1830.53
    	 Name: C:, TotalSpace: 119.77
    	 Name: H:, TotalSpace: 465.76
    	 Name: F:, TotalSpace: 2094.25
    	 Name: G:, TotalSpace: 97.65
    Id: 7816e947-e6ed-4def-b430-515c4590e2fc Name: SP3DSMP2
    	 Name: D:, TotalSpace: 136.73
    Id: 96688538-af1a-437d-8547-2e03293e44aa Name: SP3DSMP3
    Id: 2fbf9545-d657-48ae-a567-8e3cf7a1a3a4 Name: SP3DSMP4
    	 Name: Z:, TotalSpace: 12.78


    Any thought what's happening here ??

    On Server...
    Id: 956632f9-7af1-4bcf-bb01-d5179539660c Name: SP3DSMP1
    Total: 31.99
    Free: 6.7
    Name: E:, TotalSpace: 1830.53
    Name: C:, TotalSpace: 119.77
    Name: H:, TotalSpace: 465.76
    Name: F:, TotalSpace: 2094.25
    Name: G:, TotalSpace: 97.65
    Id: 7816e947-e6ed-4def-b430-515c4590e2fc Name: SP3DSMP2
    Total: 8
    Free: 4.08
    Name: C:, TotalSpace: 68.32
    Name: D:, TotalSpace: 136.73
    Name: G:, TotalSpace: 68.48
    Name: E:, TotalSpace: 34.1
    Name: F:, TotalSpace: 68.48
    Id: 96688538-af1a-437d-8547-2e03293e44aa Name: SP3DSMP3
    Total: 3.94
    Free: 1.16
    Name: E:, TotalSpace: 232.82
    Name: D:, TotalSpace: 203.5
    Name: C:, TotalSpace: 29.29
    Id: 2fbf9545-d657-48ae-a567-8e3cf7a1a3a4 Name: SP3DSMP4
    Total: 8
    Free: 2.57
    Name: E:, TotalSpace: 232.82
    Name: D:, TotalSpace: 170.02
    Name: C:, TotalSpace: 50.01
    Name: Z:, TotalSpace: 12.78
    Name: G:, TotalSpace: 279.46
    On Client...
    Id: 956632f9-7af1-4bcf-bb01-d5179539660c Name: SP3DSMP1
    Total: 31.99
    Free: 6.7
    Name: E:, TotalSpace: 1830.53
    Name: C:, TotalSpace: 119.77
    Name: H:, TotalSpace: 465.76
    Name: F:, TotalSpace: 2094.25
    Name: G:, TotalSpace: 97.65
    Id: 7816e947-e6ed-4def-b430-515c4590e2fc Name: SP3DSMP2
    Name: D:, TotalSpace: 136.73
    Id: 96688538-af1a-437d-8547-2e03293e44aa Name: SP3DSMP3
    Id: 2fbf9545-d657-48ae-a567-8e3cf7a1a3a4 Name: SP3DSMP4
    Name: Z:, TotalSpace: 12.78

    riaservices silverlight4

  • MisterGoodcat

    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.

  • sunitjoshi

    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

    <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:DataFiel

  • MisterGoodcat

    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.

  • sunitjoshi

    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.