Problem retrieving collection fields

Thread is closed for posting
2 posts, 0 answers
  1. Marcus
    Marcus avatar
    5 posts
    Member since:
    Sep 2012

    Posted 19 Jun 2009 Link to this post


    I have a couple of persistence enabled objects, one of which has a list of the other as it's content.

    public class ListedClass 
        public string theText; 
    public class Container 
        public IList<ListedClass> fields; 

    I used forward mapping to create a MySql database.

    Then I can happily create a Container class with a list of ListedClass inside it, put some values into theText of each ListedClass object and write it to the database using scope.Add, and I can confirm that it's all there in the database as expected.  Even when I retrieve the objects using the same scope as they were written with, all of the data comes back fine.

    But if I create a new scope and use that to read back the Container class, I still get a list of ListedClass objects, and there are the right number of them, but the string field inside each one is set to null.  Of course the same thing happens if I start the app again and just try to read the values.  Strangely enough, after writing a Container class, if I retrieve all of the Container classes in the database, the one I just wrote has the correct data, and all of the pre-existing ones have null strings.

    Is there something obvious that I'm doing wrong?  I know the write to the database is correct because I can do queries outside of OpenAccess ORM and the data is fine.

    I've tried doing things like setting the fetchplan for the scope to include "All", but that didn't help.

    I've also tried manually refreshing the ListedClass objects after retrieving them, but that doesn't help either.

    I've also set the scope's transaction properties to AutomaticBegin = true;

    The code I'm using to retrieve the data is:

    var resultobj = from c in scope.Extent<Container>() select c; 
    return resultobj.ToList<Container>(); 

    Can someone tell me what I'm doing wrong?



  2. PetarP
    PetarP avatar
    754 posts

    Posted 23 Jun 2009 Link to this post

    Hi Marcus,
    the problem with your project is that you are using public fields instead of private fields and public properties. What you need to do is to change your fields to private and encapsulate them with public properties. This way everything should work out fine. Please let us know if this works for you.

    All the best,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top