This is a migrated thread and some comments may be shown as answers.

Relationships are null despite Include and Association

1 Answer 42 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kevin
Top achievements
Rank 1
Kevin asked on 15 Sep 2011, 04:47 PM
Hi all,

Apologies if this is a stupid question, but I'm having a mental block.

I have a set of classes which have relationships between them (as FKs in the database), for example:

public partial class ProjectProfile
{
    private long _projectId;
    public virtual long ProjectId
    {
        get
        {
        return this._projectId;
        }
        set
        {
        this._projectId = value;
        }
    }
     
    // ... more class members
     
    private Project _project;
    public virtual Project Project
    {
        get
        {
        return this._project;
        }
        set
        {
        this._project = value;
        }
    }  
}

I've added a metadata class like so:

[MetadataTypeAttribute(typeof(ProjectProfileMetaData))]
public partial class ProjectProfile
{
    internal sealed class ProjectProfileMetaData
    {
        [Include]
        [Association("Project", "ProjectId", "ProjectId")]
        public Project Project { get; set; }
    }
}

I then rebuild, and re-run the data services wizard to update the WCF service definition.

However, when I try to retrieve the objects in my consuming class via the following:

ILookup<string, ProjectProfile> profiles = (from pp in dataManager.ProjectProfiles
    where ((pp.ProfileYear == startDate.Year && pp.ProfileMonth >= startDate.Month) || pp.ProfileYear >= startDate.Year)
        && ((pp.ProfileYear == endDate.Year && pp.ProfileMonth <= endDate.Month) || pp.ProfileYear < endDate.Year)
    select pp).OrderBy(pp => pp.ProfileYear).ThenBy(pp => pp.ProfileMonth).ToLookup(pp => pp.Project.ProjectStatus.ProjectShowsOn);

the project entity (pp.Project) is null.

Do I need to manually edit the DataManager class to add .Include("Project") to the query? I would assume not, because I assume the Include attribute (in System.ServiceModel.DomainServices.Server - not the ones in Telerik.OpenAccess) is supposed to indicate to the ORM autogeneration stuff that it should add it.

Or am I missing something else entirely?

Cheers!

1 Answer, 1 is accepted

Sort by
0
Ady
Telerik team
answered on 21 Sep 2011, 09:32 AM
Hi Kevin,

 Does executing the LINQ query directly in a console application (without data services anywhere in the picture) work? If that works we can try and narrow down to the actual problem with regards to the generated data services code.
Also, if possible can you send me  a sample project where I can observe this behavior? This will help in providing a solution sooner.

Looking forward to helping you further.

Regards,
Ady
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's SQL Server Community Awards. We are competing in TWO categories and every vote counts! VOTE for Telerik NOW >>

Tags
General Discussions
Asked by
Kevin
Top achievements
Rank 1
Answers by
Ady
Telerik team
Share this question
or