Search   

Sunday, February 05, 2012

Support » Support Forum

Register  Login

 Menu  
 
    

 Welcome!  
 


Welcome to the NDO support forum!

kreis.gif Please register/login at the site if you want to post a thread. We sometimes copy support mails of common interest to the forum. They appear with anonymous sender.
kreis.gif Please post your messages in English language if possible. You can do your posts also in German, we will translate your post and our answer so that all users of the forum can read your posts.
kreis.gif The forum software requires that javascript is enabled.
kreis.gif Please do not insert licence information or licence keys in forum posts.
kreis.gif If you know a good answer to a post of another user, feel free to reply!
kreis.gif The forum is monitored. We reserve the right to remove posts we consider not to be useful for other forum users.

   Print   

      
 NDO Support Forum  
 
SearchForum Home
  NDO-Forum postings in english please, if possible.  Developing with NDO  Persisting prim...
 Persisting primitive arrays
 
 2/1/2007 5:17:58 AM
stunney
1 posts


Persisting primitive arrays
 Modified By stunney  on 2/1/2007 6:19:42 AM)
Hello, I was hoping that someone might be able to help me on a subject that is probably easily fixed, but I have not yet found a solution.
Suppose the following class

[NDOPersistent]
public class MyClass {
private int m_Value = 0;
private int[] m_Stuff;

public int Value{ get{ return m_Value; } }
public int[] Stuff{ get{ return m_Stuff; } set { m_Stuff = value; } }
}

When I build my solution, and the mapping file is generated, there is no Field node under MyClass to show that m_Stuff will be persisted.
Thoughts?
 2/1/2007 8:44:31 AM
Mirko
109 posts
5th


Re: Persisting primitive arrays

Hi Stunney,

thanks for your interest in NDO. There is no way for NDO to know, how it should persist your int array in a relational database. That's the reason, why NDO ignores your array. There are two main options you can choose if you want to persist your array: the first is storing the values in a blob column of your table, the second is to store the values in an own table with a foreign key column that connects to the MyClass table.

To achieve the first scenario you define a persitent byte[] variable. Implement the IPersistenceNotifiable interface and use the OnLoading and OnSaving functions to convert the byte[] to the int[] and vice versa. Make sure to mark your object as dirty, if you change the content of the int[] array:
((IPersistenceCapable)this).NDOMarkDirty();
A similar approach would be to convert your int[] to a persistent string variable.

In the second scenario you need a special class holding the integer, and define a 1:n relation to that class:

[NDOPersistent]
public class Stuff
{
    public Stuff(int val)
    {
        this.value = val;
    }
    int value;
}

[NDOPersistent]
public class MyClass {
private int m_Value = 0;
[NDORelation(RelationInfo.Composite)]
List myStuff = new List();
public void AddStuff(int val)
{
    myStuff.Add(new Stuff(val));
}
... // Generate accessor functions and properties with the AddAccessor button.

public int Value{ get{ return m_Value; } }
}

I hope, that helps. If you have further questions, please ask.

Best Regards:
Mirko

  NDO-Forum postings in english please, if possible.  Developing with NDO  Persisting prim...
  SearchSearch  Forum HomeForum Home