0

I am using Binding on the DataGrid columns and have used the Navigation Properties in the past with expected results. I am getting the other fields to show just not these two that use Navigation Properties. The properties are spelled correctly as for the fields they represent. I am using Entity Framework for backend via WCF. When I check the CalenderChange object that is returning via the WCF function, I can see the Navigation Property and the readonly field is _Firstname and has the value I expect. I tried changing the Binding to Binding="{Binding Personnel._Firstname} without success.

Include it in the query:

db.CalenderChanges.Include("Personnel").Where({condition}).ToList()

XAML:

<sdk:DataGridTextColumn Header="First Name" Binding="{Binding Personnel.Firstname}"  Width="100" />
<sdk:DataGridTextColumn Header="Last Name" Binding="{Binding Personnel.Lastname}"  Width="100" />

What am I missing? Thanks...

OneFineDay
  • 9,004
  • 3
  • 26
  • 37
  • What is your DataGrid bound to? `IEnumerable` or some such? In that case you should use just `Firstname`, not `Personnel.Firstname`. – icebat Nov 18 '13 at 08:23
  • No, it is bound to the CalenderChange collection, Personnel is the navigation property. – OneFineDay Nov 18 '13 at 20:40

1 Answers1

2

If you are using WCF Ria Services, the usual reason is because using Include("Personnel") is not sufficient.

For Silverlight to get the Personnel data, you need both conditions

  1. db.CalenderChanges.Include("Personnel") so that Personnel is returned from database

  2. The metadata for Personnel navigation property is marked with [Include] attribute, so that Personnel is marshalled by WCF to the client. see https://stackoverflow.com/a/5332188/34461

sample

// ExtraMetadata.cs
// Add Reference to System.ComponentModel.DataAnnotations.dll

namespace MyModel
{
  using System.ComponentModel.DataAnnotations;

  // This attribute tells Ria Services that the metadata
  // for the CalendarChange class is in CalenderChange.MetaData class
  [MetadataType(typeof(CalenderChange.MetaData)]
  public partial class CalenderChange {
    public class MetaData {

        // adding this attribute tells RIA services 
        // to also send this property across the wire
        [Include]
        public MetaData Personnel { get; set; }
    }
  }
}

Reference:

  1. MSDN How to add metadata classes.

  2. MSDN IncludeAttribute

Community
  • 1
  • 1
Chui Tey
  • 5,436
  • 2
  • 35
  • 44
  • Ok, where am I adding this, the model.Designer.vb file? – OneFineDay Nov 19 '13 at 05:55
  • I see a SoapInclude or XmlInclude attributes, not Include?? – OneFineDay Nov 19 '13 at 06:04
  • The other thing is, I didn't have to do that for the other navigation properties on my other DataGrids... – OneFineDay Nov 19 '13 at 17:21
  • If those entities were loaded separately then it wouldn't be necessary. You should you Fiddler to examine the response. – Chui Tey Nov 19 '13 at 23:54
  • I just loaded Fiddler a couple of weeks ago and ran it a few times. I have no idea how to use it, but I am working on it. If you have some hints for me - I would love it. Thanks for your time! – OneFineDay Nov 20 '13 at 00:06
  • When I debug the client I see there is no navigation properties have been serialized thru. I made a workaround by making a complex type and that gathers all the properties I need then passes a `List` of this complex type to the client, then bind on the properties and viola. I would have loved to been able to do this thru serialization, but alas no one was able to tell me how. I will keep searching and fix this when able. – OneFineDay Nov 21 '13 at 18:08
  • I think [this](http://msdn.microsoft.com/en-us/library/ee358709.aspx) may be the answer too. – OneFineDay Nov 22 '13 at 01:07
  • No, I didn't understand how it works. I was looking for that code and did not find it - so I am now assuming I would make that class. – OneFineDay Nov 22 '13 at 14:57
  • Yes, add the class and it should work. Also see the two references I provided in the solution. – Chui Tey Nov 23 '13 at 05:55
  • Absolutely! I still wonder why I did not have to do this to some other Navigation Properties. Anyway it a great design to know. Thanks – OneFineDay Nov 23 '13 at 06:16