c# objects

I read from a xml file in my web service. Lets say for example, in the xml there are information about one or more
products, such as price, quantity, color etc. Now i have to save all the information for each product in the database.
Since xml queries are relatively fast, would it be better to create a product class/object and then pass these objects
to a function which will save the information to the database instead of quering xml for each attribute value and then
passing it to a function to save each product one by one.
singsunnAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VoloxCommented:
Your question is a little confusing because of the teminology you are using...  For example, you say "quering xml for each attribute value" and you seem to be referring to a product which one would normally have contained in a node.  Perhaps posting a sample of the XML or an XML schema would help...

However, given what I have here to go off of I would say this... unless you are bulk loading the rows into the database, the database operations are going to occur row by row regardless of how you pass the data to the data access function.  The primary driver for whether you pass the data access function a set of items or a single item at a time is usually based on whether there is going to be a transaction surrounding the operation across multiple rows (in which case you would want to pass the entire set so that the transaction logic can stay inside the data access method).

I think the issue of how you pass the information to your data access method is independent of how you load the data from the XML file.  For that, if the XML is totally within your control and you can use object deserialization, then that is a nice easy way to get the data loaded.  If it isn't under your control or object deserialization doesn't work, then you might give consideration to loading the XML into a dataset.  It is usually easier and less code to use one of those methods than to write the XML parsing into object by hand.  The exception would be if you have extremely large XML files, in which case you are probably going to want to check that your selected method performs and potentially move to using a more efficient XML parser.  In that even you might also consider only loading sub-sets of the file at a time so that you don't eat up all your memory with objects or dataset content.

If I'm off hte mark, post with clarification and I will try to help further.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.