By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,950 Members | 1,579 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,950 IT Pros & Developers. It's quick & easy.

Storing objects in SQL Server table

P: n/a
Hello. I need to store custom objects in a SQL Server 2000 table. Which is
the easiest way to do it? Do I need to write methods to store each attribute
separately from C# app to the table and the opposite as well?

Regards,

Diego F.
Nov 16 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Haven't had cause to do it myself but you derive from ISerializable, and
overrride the method that it forces you to override (for serializing) aswell
as a special constructor which takes a SerializationInfo and something else
(for deserializing). These two methods are where you choose what data you
want to serialize, by adding and retrieving name-value pairs.
In the Serialization namespace, there's then a class called something like
'BinaryFormatter' which takes an array of the serializable objects and
converts them to a binary stream.
Look on msdn under 'ISerializable'.
"Diego F." <di*****@NOterra.es> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello. I need to store custom objects in a SQL Server 2000 table. Which is
the easiest way to do it? Do I need to write methods to store each attribute separately from C# app to the table and the opposite as well?

Regards,

Diego F.

Nov 16 '05 #2

P: n/a
But if I store the objects directly as binary data, can I make querys in the
table? I'm thinking of writing methods to map the attributes to table
fields.

Regards,

Diego F.

"Beeeeeves" <beeeeeeeeev@ves> escribió en el mensaje
news:OU**************@TK2MSFTNGP11.phx.gbl...
Haven't had cause to do it myself but you derive from ISerializable, and
overrride the method that it forces you to override (for serializing) aswell as a special constructor which takes a SerializationInfo and something else (for deserializing). These two methods are where you choose what data you
want to serialize, by adding and retrieving name-value pairs.
In the Serialization namespace, there's then a class called something like
'BinaryFormatter' which takes an array of the serializable objects and
converts them to a binary stream.
Look on msdn under 'ISerializable'.
"Diego F." <di*****@NOterra.es> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello. I need to store custom objects in a SQL Server 2000 table. Which is the easiest way to do it? Do I need to write methods to store each

attribute
separately from C# app to the table and the opposite as well?

Regards,

Diego F.


Nov 16 '05 #3

P: n/a
My first guess is that if you want to use the serialized data for purposes
other than deserializing, i.e. run a query on it while it's deserialized,
then you would not use ISerializable and write a custom serialization
function to produce the serialized data in the format you will be able to
query.
But if you study the format of the binary data once it's serialized it may
be that you can devise a query to do it.
"Diego F." <di*****@NOterra.es> wrote in message
news:uf**************@TK2MSFTNGP12.phx.gbl...
But if I store the objects directly as binary data, can I make querys in the table? I'm thinking of writing methods to map the attributes to table
fields.

Regards,

Diego F.

"Beeeeeves" <beeeeeeeeev@ves> escribió en el mensaje
news:OU**************@TK2MSFTNGP11.phx.gbl...
Haven't had cause to do it myself but you derive from ISerializable, and
overrride the method that it forces you to override (for serializing) aswell
as a special constructor which takes a SerializationInfo and something

else
(for deserializing). These two methods are where you choose what data you
want to serialize, by adding and retrieving name-value pairs.
In the Serialization namespace, there's then a class called something like 'BinaryFormatter' which takes an array of the serializable objects and
converts them to a binary stream.
Look on msdn under 'ISerializable'.
"Diego F." <di*****@NOterra.es> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello. I need to store custom objects in a SQL Server 2000 table.

Which is the easiest way to do it? Do I need to write methods to store each

attribute
separately from C# app to the table and the opposite as well?

Regards,

Diego F.



Nov 16 '05 #4

P: n/a
But is it difficult to write a method that just maps the object attributes
into a table fields?

Regards,

Diego F.

"Beeeeeves" <beeeeeeeeev@ves> escribió en el mensaje
news:OZ**************@TK2MSFTNGP09.phx.gbl...
My first guess is that if you want to use the serialized data for purposes
other than deserializing, i.e. run a query on it while it's deserialized,
then you would not use ISerializable and write a custom serialization
function to produce the serialized data in the format you will be able to
query.
But if you study the format of the binary data once it's serialized it may
be that you can devise a query to do it.
"Diego F." <di*****@NOterra.es> wrote in message
news:uf**************@TK2MSFTNGP12.phx.gbl...
But if I store the objects directly as binary data, can I make querys in

the
table? I'm thinking of writing methods to map the attributes to table
fields.

Regards,

Diego F.

"Beeeeeves" <beeeeeeeeev@ves> escribió en el mensaje
news:OU**************@TK2MSFTNGP11.phx.gbl...
Haven't had cause to do it myself but you derive from ISerializable, and overrride the method that it forces you to override (for serializing)

aswell
as a special constructor which takes a SerializationInfo and something

else
(for deserializing). These two methods are where you choose what data you want to serialize, by adding and retrieving name-value pairs.
In the Serialization namespace, there's then a class called something like 'BinaryFormatter' which takes an array of the serializable objects and
converts them to a binary stream.
Look on msdn under 'ISerializable'.
"Diego F." <di*****@NOterra.es> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
> Hello. I need to store custom objects in a SQL Server 2000 table.

Which
is
> the easiest way to do it? Do I need to write methods to store each
attribute
> separately from C# app to the table and the opposite as well?
>
> Regards,
>
> Diego F.
>
>



Nov 16 '05 #5

P: n/a
Diego F. wrote:
But is it difficult to write a method that just maps the object attributes
into a table fields?
Let me say that it took me more than a year and 3.5 MB of C# code :). The
technique you're looking for is 'O/R mapping'.

Frans.

--
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP

Regards,

Diego F.

"Beeeeeves" <beeeeeeeeev@ves> escribió en el mensaje
news:OZ**************@TK2MSFTNGP09.phx.gbl...
My first guess is that if you want to use the serialized data for purposes
other than deserializing, i.e. run a query on it while it's deserialized,
then you would not use ISerializable and write a custom serialization
function to produce the serialized data in the format you will be able to
query.
But if you study the format of the binary data once it's serialized it may
be that you can devise a query to do it.
"Diego F." <di*****@NOterra.es> wrote in message
news:uf**************@TK2MSFTNGP12.phx.gbl...
But if I store the objects directly as binary data, can I make querys in

the
table? I'm thinking of writing methods to map the attributes to table
fields.

Regards,

Diego F.

"Beeeeeves" <beeeeeeeeev@ves> escribió en el mensaje
news:OU**************@TK2MSFTNGP11.phx.gbl...
> Haven't had cause to do it myself but you derive from ISerializable, and > overrride the method that it forces you to override (for serializing)
aswell
> as a special constructor which takes a SerializationInfo and something
else
> (for deserializing). These two methods are where you choose what data

you
> want to serialize, by adding and retrieving name-value pairs.
> In the Serialization namespace, there's then a class called something

like
> 'BinaryFormatter' which takes an array of the serializable objects and
> converts them to a binary stream.
> Look on msdn under 'ISerializable'.
>
>
> "Diego F." <di*****@NOterra.es> wrote in message
> news:%2****************@TK2MSFTNGP10.phx.gbl...
> > Hello. I need to store custom objects in a SQL Server 2000 table.

Which
is
> > the easiest way to do it? Do I need to write methods to store each
> attribute
> > separately from C# app to the table and the opposite as well?
> >
> > Regards,
> >
> > Diego F.
> >
> >
>
>



Nov 16 '05 #6

P: n/a
Let me say that it took me more than a year and 3.5 MB of C# code :). The
technique you're looking for is 'O/R mapping'.

Frans.


Really?!!! If you have already the tables in SQL Server is a question of
mapping the values of the attributes. The only problem I see is mapping a
collection.

Maybe I have to use a thirds tool. I have seen one from Mongoose Solutions
(Objectz.NET)

Regards,

Diego F.
Nov 16 '05 #7

P: n/a
Diego F. wrote:
Let me say that it took me more than a year and 3.5 MB of C# code :). The
technique you're looking for is 'O/R mapping'.

Frans.


Really?!!! If you have already the tables in SQL Server is a question of
mapping the values of the attributes. The only problem I see is mapping a
collection.


You mean a collection of entities, like a set of 'customers' ? Our tool,
LLBLGen Pro, creates these classes for you. Our tool grabs the schema in the
db and creates the classes you need, complete with O/R mapping features.

Most of the code is in the housekeeping code behind the scenes. You save a
'customer' object, but it has to save also its related new order objects and
the related order row objects related to order etc.

Frans.

--
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP
Nov 16 '05 #8

P: n/a
What I have is that:

- A first object that has simple types: int, float and string. Call it
Customer.
- A second object that is a collection of Customer objects: that is:

public class Customers: CollectionBase
{
public Customer this [int index]
{
get { return (Customer)this.List[index]; }
}
public void Add(Customer c)
{
this.List.Add(c);
}
}

- A third object that includes int, string, float and Customers.

I work with the third type objects and in a point of the application, I have
a Hashtable with these objects. What I need is storing them in the database
and later make some queries. I don't need to convert to objects again.

Can you help me?

Regards,

Diego F.
"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> escribió en el
mensaje news:xn***************@msnews.microsoft.com...
Diego F. wrote:
Let me say that it took me more than a year and 3.5 MB of C# code :). The technique you're looking for is 'O/R mapping'.

Frans.

Really?!!! If you have already the tables in SQL Server is a question of
mapping the values of the attributes. The only problem I see is mapping a collection.


You mean a collection of entities, like a set of 'customers' ? Our tool,
LLBLGen Pro, creates these classes for you. Our tool grabs the schema in

the db and creates the classes you need, complete with O/R mapping features.

Most of the code is in the housekeeping code behind the scenes. You save a
'customer' object, but it has to save also its related new order objects and the related order row objects related to order etc.

Frans.

--
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP

Nov 16 '05 #9

P: n/a
Diego F. wrote:
What I have is that:

- A first object that has simple types: int, float and string. Call it
Customer.
- A second object that is a collection of Customer objects: that is:

public class Customers: CollectionBase
{
public Customer this [int index]
{
get { return (Customer)this.List[index]; }
}
public void Add(Customer c)
{
this.List.Add(c);
}
}

- A third object that includes int, string, float and Customers.

I work with the third type objects and in a point of the application, I have
a Hashtable with these objects. What I need is storing them in the database
and later make some queries. I don't need to convert to objects again.
You mean:
Customer (first)
which has a collection Orders (second)
forming
the third object?

if so, of course this is handled.

Frans

Can you help me?

Regards,

Diego F.
"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> escribió en el
mensaje news:xn***************@msnews.microsoft.com...
Diego F. wrote:

> Let me say that it took me more than a year and 3.5 MB of C# code :). The > technique you're looking for is 'O/R mapping'.
>
> Frans.
>

Really?!!! If you have already the tables in SQL Server is a question of
mapping the values of the attributes. The only problem I see is mapping a collection.


You mean a collection of entities, like a set of 'customers' ? Our tool,
LLBLGen Pro, creates these classes for you. Our tool grabs the schema in

the
db and creates the classes you need, complete with O/R mapping features.

Most of the code is in the housekeeping code behind the scenes. You save a
'customer' object, but it has to save also its related new order objects

and
the related order row objects related to order etc.

Frans.

--
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP


--
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP
Nov 16 '05 #10

P: n/a
Well, it would depend largely on what the object's attributes are!

You're not going to get something packaged and out-of-the-box, it would sound like you'll have to write an algorithm to do what you want.

Remember the meaning of "I.T." - Information Technology. Go forth and apply some of the Technology that you understand to the Information you've got.
"Diego F." wrote:
But is it difficult to write a method that just maps the object attributes
into a table fields?

Regards,

Diego F.

"Beeeeeves" <beeeeeeeeev@ves> escribió en el mensaje
news:OZ**************@TK2MSFTNGP09.phx.gbl...
My first guess is that if you want to use the serialized data for purposes
other than deserializing, i.e. run a query on it while it's deserialized,
then you would not use ISerializable and write a custom serialization
function to produce the serialized data in the format you will be able to
query.
But if you study the format of the binary data once it's serialized it may
be that you can devise a query to do it.
"Diego F." <di*****@NOterra.es> wrote in message
news:uf**************@TK2MSFTNGP12.phx.gbl...
But if I store the objects directly as binary data, can I make querys in

the
table? I'm thinking of writing methods to map the attributes to table
fields.

Regards,

Diego F.

"Beeeeeves" <beeeeeeeeev@ves> escribió en el mensaje
news:OU**************@TK2MSFTNGP11.phx.gbl...
> Haven't had cause to do it myself but you derive from ISerializable, and > overrride the method that it forces you to override (for serializing)
aswell
> as a special constructor which takes a SerializationInfo and something
else
> (for deserializing). These two methods are where you choose what data

you
> want to serialize, by adding and retrieving name-value pairs.
> In the Serialization namespace, there's then a class called something

like
> 'BinaryFormatter' which takes an array of the serializable objects and
> converts them to a binary stream.
> Look on msdn under 'ISerializable'.
>
>
> "Diego F." <di*****@NOterra.es> wrote in message
> news:%2****************@TK2MSFTNGP10.phx.gbl...
> > Hello. I need to store custom objects in a SQL Server 2000 table.

Which
is
> > the easiest way to do it? Do I need to write methods to store each
> attribute
> > separately from C# app to the table and the opposite as well?
> >
> > Regards,
> >
> > Diego F.
> >
> >
>
>



Nov 16 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.