Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hallo fellow coders

I have this strange behavior on my Silverlight project working with RIA Services and ADO.NET Entity Data Model.

On my Data Model I have a master table (PRT_NEWS) with two foreign keys to two related tables (PRT_EXT_NEWS_ESTADOS and PRT_EXT_NEWS_IMAGENS).

Relationships between the master table and the related tables are done exactly the same way.

Domain service and Domain Service Metadata have the needed information done the same way.

The goal is to have a master Entity in the Silverlight project that has all the data from the master table and also the data from the related tables.

RIA is supposed to take care of this and exposes all data (master and related tables data) as a single entity.

In the Silverlight project data is loaded using a LoadOperation. Nothing fancy here.

When I stop execution and check what’s being returned on the entity collection I can see that all data from master table is there as all data from the first related table (PRT_EXT_NEWS_ESTADOS) but the entity that should hold the data from the second related table is always null.

Googling around I found some hints to try.

Tried “Lazy loading” to false.
Tried the [Include] decoration on the master table member that holds the related table entity.
Tried the .Include(“PRT_EXT_NEWS_IMAGENS”) on the Get method of the master table.
Even tried to change the order of member declaration in the metadata.

None of those worked and, surprisingly, the PRT_EXT_NEWS_ESTADOS member on the master table has nothing of this and works just fine.

Is there anyone familiar with this behavior? What was the solution or workaround?

Thanks
Posted
Updated 26-Feb-14 2:55am
v2

1 solution

I've solved it myself.

Here's the thing:

One combination I didn’t try before was to decorate the member with the [Include] AND complement the get method with the .Include(“PRT_EXT_NEWS_IMAGENS”).

It seems to be working now.

C#
[MetadataTypeAttribute(typeof(PRT_NEWS.PRT_NEWSMetadata))]
public partial class PRT_NEWS
{
    internal sealed class PRT_NEWSMetadata
    {
        private PRT_NEWSMetadata()
        {
        }

        public bool ATIVO { get; set; }
        public string CONTEUDO { get; set; }
        public DateTime DATA_CRIACAO { get; set; }
        public DateTime DATA_LIMITE { get; set; }
        public DateTime DATA_PUBLICACAO { get; set; }
        public int FK_ID_ESTADO { get; set; }
        public int FK_ID_IMAGEM_MAIN { get; set; }
        public Guid GUID { get; set; }
        public int ID { get; set; }
        [Include]
        public PRT_EXT_NEWS_ESTADOS PRT_EXT_NEWS_ESTADOS { get; set; }
        [Include]
        public PRT_EXT_NEWS_IMAGENS PRT_EXT_NEWS_IMAGENS { get; set; }
        public string SINOPSE { get; set; }
        public string TITULO { get; set; }
    }
}


C#
public IQueryable<PRT_NEWS> GetPRT_NEWS()
{
    return this.ObjectContext.PRT_NEWS.Include("PRT_EXT_NEWS_IMAGENS").Include("PRT_EXT_NEWS_ESTADOS");
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900