Relationships are null despite Include and Association

Thread is closed for posting
2 posts, 0 answers
  1. Kevin
    Kevin avatar
    9 posts
    Member since:
    Sep 2010

    Posted 15 Sep 2011 Link to this post

    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!
  2. Ady
    Admin
    Ady avatar
    589 posts

    Posted 21 Sep 2011 Link to this post

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

Back to Top