Search code examples
c#silverlightentity-frameworkwcf-ria-services

Ria Services and navigation property issues


I'm encountering an issue using Silverlight4, Ria Services and Entity Framework.

From my sl client I try to get some data through ria services, in my domainService class this method gets called:

public IQueryable<LastMinuteWachtLijstPromotie> GetLastMinuteWachtLijstPromoties(){
  IQueryable<LastMinuteWachtLijstPromotie> list = (IQueryable<LastMinuteWachtLijstPromotie>)this.ObjectContext.LastMinuteWachtLijstPromoties.Include("Promotie");

  return (from LastMinuteWachtLijstPromotie lwmp in list where lwmp.Actief select lwmp);
}

when I check the contents of the list, in debug mode, it's filled with objects of type LastMinuteWachtLijstPromotie. these objects have a navigation property to an Object named Promotie. And i can access the properties of these Promotie objects.

On the silveright client however a method gets invoked when loading is complete:

public void OnLoadEntitiesCompleted(ServiceLoadResult<T> result) {

}

In this method I get all the requested LastMinuteWachtLijstPromotie objects as expected, the property Promotie however is null.

I have set the [Include] tag on the property Promotie in the auto generated metadata class and I use the .Include("Promotie")

These same methods are used for different objects from my Domain Model, this works perfectly. Also, I cannot seem to find differences in the .edmx file with the database mappings and navigation properties.

Has anyone encountered the same issue or know a solution for it?

the metadata classes:

[MetadataTypeAttribute(typeof(LastMinuteWachtLijstPromotie.LastMinuteWachtLijstPromotieMetadata))]
        public partial class LastMinuteWachtLijstPromotie
        {

            // This class allows you to attach custom attributes to properties
            // of the LastMinuteWachtLijstPromotie class.
            //
            // For example, the following marks the Xyz property as a
            // required property and specifies the format for valid values:
            //    [Required]
            //    [RegularExpression("[A-Z][A-Za-z0-9]*")]
            //    [StringLength(32)]
            //    public string Xyz { get; set; }
            internal sealed class LastMinuteWachtLijstPromotieMetadata
            {

                // Metadata classes are not meant to be instantiated.
                private LastMinuteWachtLijstPromotieMetadata()
                {
                }

                public int AlertId { get; set; }

                public string ArtikelNummer { get; set; }

                public Nullable<int> ArtikelVariant { get; set; }

                public int LastMinuteWachtLijstPromotieId { get; set; }

                [Include]
                public Promotie Promotie { get; set; }

                public int PromotieArtikelId { get; set; }

                public int PromotieId { get; set; }

                public bool Actief { get; set; }

                public DateTime Aanmaakdatum { get; set; }
            }
        }


        [MetadataTypeAttribute(typeof(Promotie.PromotieMetadata))]
    public partial class Promotie
    {

        // This class allows you to attach custom attributes to properties
        // of the Promotie class.
        //
        // For example, the following marks the Xyz property as a
        // required property and specifies the format for valid values:
        //    [Required]
        //    [RegularExpression("[A-Z][A-Za-z0-9]*")]
        //    [StringLength(32)]
        //    public string Xyz { get; set; }
        internal sealed class PromotieMetadata
        {

            // Metadata classes are not meant to be instantiated.
            private PromotieMetadata()
            {
            }

            public string ActieType { get; set; }

            public string AssortimentsManagerNaam { get; set; }

            public string AssortimentsManagerTeamIds { get; set; }

            [Display(Name = "Commerciele tekst")]
            [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Nokavision.ReclameFolder.UI.Web.Resources.ValidationResources))]            
            public string CommercieleTekst { get; set; }

            [Display(Name = " ")]
            public string CommercieleTekstDetails { get; set; }

            [Include]
            public Frame Frame { get; set; }

            public Nullable<int> FrameId { get; set; }

            public Nullable<DateTime> LastMinuteWijzigingsDatum { get; set; }

            public string Opmerkingen { get; set; }

            [Display(Name = "Op wachtlijst")]
            public Nullable<bool> OpWachtLijst { get; set; }

            //public Nullable<int> PromotieCopyId { get; set; }

            public int PromotieId { get; set; }

            [Include]
            public EntityCollection<PromotieLeverancier> PromotieLeveranciers { get; set; }

            [Include]
            public EntityCollection<PromotieMutatie> PromotieMutaties{ get; set; }

            //public Nullable<int> PromotieOrigineleId { get; set; }

            [Include]
            public EntityCollection<PromotieSymbool> PromotieSymbolen { get; set; }

            public string Status { get; set; }

            [Display(Name = "Promotie inhoud")]
            public string PromotieInhoud { get; set; }

            [Display(Name = "Promotie eenheid")]
            public string PromotieEenheid { get; set; }

            [Display(Name = "Promotie prijs")]
            public decimal PromotiePrijs { get; set; }
        }
    }

Solution

  • Add the Composition attribute to the property Promotie property of the LastMinuteWachtLijstPromotieMetadata class. Then it should work.

    public partial class LastMinuteWachtLijstPromotie {
      internal sealed class LastMinuteWachtLijstPromotieMetadata{
        [Include]
        [Composition]
        public Promotie Promotie { get; set; }
      }
    }