locked
Losing objects within POCO collection in association RRS feed

  • Question

  • I'm developing a Silverlight 4 app with EF 4 and RIA services.  I'm somewhat new to RIA and I'm experiencing a wierd problem where I'm losing all objects except one within a collection.  I've got an entity object named Employee, and I've created a POCO class named Job.  I've created the following association on the Employee.cs:

    [Include] 
    [Association("JobAssocation", "EmployeeId", "EmployeeId")]
    [Display(AutoGenerateField = false)]
    public List<Job> Jobs { get; set; }

     I don't have a table named Job in the database or model, the rules are rather complex, so I built a POCO to represent the job with rate and I'm populating the Job collection from the domain service.  When I just the job collection within the service, I have 7 items, but when it returns to the client, I only have one.  I have one job for all my employees. I've verified that all job objects have the same EmployeeId within the domain service.

    Any idea what's going on?

    Thanks,

    Steve

     

    Thursday, November 24, 2011 4:11 PM

Answers

  • Hi Steve,

    Jobs are declared like this?

        [DataContract()]
        public class Something
        {
            [Key]
            [DataMember]
            public string id { get; set; }
            public decimal am { get; set; }
        }
    

    Maybe you miss the Key attribute?

    Thursday, November 24, 2011 4:51 PM

All replies

  • Hi Steve,

    Jobs are declared like this?

        [DataContract()]
        public class Something
        {
            [Key]
            [DataMember]
            public string id { get; set; }
            public decimal am { get; set; }
        }
    

    Maybe you miss the Key attribute?

    Thursday, November 24, 2011 4:51 PM
  • Thank you so much Greg.  When you asked me about the Key property, I realized I had the Key attribute on a field that was not a true key.  It was only bringing one object to the client.  After I put the Key property on distinct properties, it worked.  Thank you for causing me to think about the Key!  -Steve

    Friday, November 25, 2011 2:05 AM