• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

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.
1 Solution
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.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now