开发者

Sql server 2005 - Returning data as XML or datatables

I have three classes

a) Parent - Which contains some properties, an Item collection and a collection of children

b) Child - Which contains some properties and an Item collection

c) Item - Which contains some properties

The relationship is depicted in the below XML structure.

<Parents>
    <Parent1>
        <Property1></Property1>
        <Property2></Property2>
        <Property3></Property3>
            <Parent1Children>
                <Child1>
                <Child1Property1></Child1Property1>
                <Child1Property2></Child1Property2>
                </Child1>
                <Child2>
                <Child2Property1></Child2Property1>
                <Child2Property2></Child2Property2>
                </Child2>
            </Parent1Children>  
        <Parent1SomeCollection>
            <Item1>
                <Item1Property1></Item1Property1>
                <Item1Property2><开发者_如何学C;/Item1Property2>
            </Item2>
            <Item2>
                <Item2Property1></Item2Property1>
                <Item2Property2></Item2Property2>
            </Item2>
        </Parent1SomeCollection>    
    </Parent1>  
</Parents>  

I need to use the data from the tables of the three classes above. I can think of the following options:-

  1. Get this structure in the form of XML from the database as depicted above from a stored procedure and use the same as XDocument in the business layer.

  2. Get in the form of 3 tables from the database them in datatable and establish relationship between the to get the data?

Which one would give optimum performance and is a better way or are there better ways to do the same?


A DataSet would hold the data better (assuming you're referring to .NET code), and maintain the relationships, while allowing you the ability to save the data in XML, and perform mass inserts and updates. So performance should be very good. Using an ORM would also be a good idea, since the ORM would give yous similar functionality, plus it may support LINQ (ORMs like Entity Framework and Linq-to-SQL).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜