Serialize in dataBase

  • Thread starter Thread starter PawelR
  • Start date Start date
P

PawelR

Hello group,
I have irrational idea but I thing that this solution is good for me.
In my apps I have custom class MyClass with few public, and private
integers, two ArrayList etc.
How serialize this class to dataBase. I need have completly object in one
place.
I know that I want create few tables and use select command but is too
slowly for me (Select for fill ArrayLists is too slow) I want get object use
SqlReader and I can't (user can't) change objects in dataBase.
PawelR
 
Thanks,
My question is not "How serialize class?" but
"How serialize class and save this in db?"
Pawel
 
PawelR said:
Hello group,
I have irrational idea but I thing that this solution is good for me.
In my apps I have custom class MyClass with few public, and private
integers, two ArrayList etc.
How serialize this class to dataBase. I need have completly object in one
place.
I know that I want create few tables and use select command but is too
slowly for me (Select for fill ArrayLists is too slow) I want get object use
SqlReader and I can't (user can't) change objects in dataBase.

I suggest you look at NHibernate, which is a framework for mapping
objects to relational databases. For more information see
http://nhibernate.sourceforge.net/

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
 
Pawel,

I made a sample, I assume that you know how to save a string in a database.

\\\Needs a form with 2 buttons.
\\\and using System.Runtime.Serialization.Formatters.Binary;
public string str;
private void button1_Click(object sender, System.EventArgs e)
{
mySerClass mine = new mySerClass();
mine.name = "pawel";
BinaryFormatter bf = new BinaryFormatter();
System.IO.MemoryStream mem = new System.IO.MemoryStream();
bf.Serialize(mem, mine);
str = Convert.ToBase64String(mem.ToArray());
}
private void button2_Click(object sender, System.EventArgs e)
{
BinaryFormatter bf = new BinaryFormatter();
System.IO.MemoryStream mem =
new System.IO.MemoryStream(Convert.FromBase64String(str));
mySerClass mine = (mySerClass)bf.Deserialize(mem);
MessageBox.Show(mine.name);
}
}
[Serializable]
public class mySerClass
{
public string name;
}
}
///

I hope this helps?

Cor
 
Thenks,
To this moment I not be shure how convert my class to binary value (for db),
now I know.
Thanks You very much, now it's simple.


Pawel
 
PawelR said:
Hello group,
I have irrational idea but I thing that this solution is good for me.
In my apps I have custom class MyClass with few public, and private
integers, two ArrayList etc.
How serialize this class to dataBase. I need have completly object in one
place.
I know that I want create few tables and use select command but is too
slowly for me (Select for fill ArrayLists is too slow) I want get object use
SqlReader and I can't (user can't) change objects in dataBase.

Deserializing can often be slower than reading values from the DB,
don't forget that. Also by storing data in a blob in a db field, you
lose the option to filter on the data. This might come as a future
enhancement of the software you're writing now.

Frans

--
 
Back
Top