c# objects

Posted on 2011-10-20
Last Modified: 2012-05-12
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.
Question by:singsunn
    1 Comment
    LVL 8

    Accepted 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

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now