This is a migrated thread and some comments may be shown as answers.
Problem retrieving collection fields
1 Answer 23 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Top achievements
Rank 1
Marcus asked on 19 Jun 2009, 08:33 AM

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?



1 Answer, 1 is accepted

Sort by
Telerik team
answered on 23 Jun 2009, 02:30 PM
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.
General Discussions
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question