开发者

What is the most efficient way to transfert data from Database to server to client?

I wonder what is the best way to transfert data from the database to the WCF service to the client between these two options:

Option 1. I have two tables in my database, "data1" and "data2". The to table are linked by "data2Id". data2Id is not unique and can be linked to more then one DATA.

data1:

dataId | data2Id
----------------
 int   | int   
 int   | int   
 ...   | ...

data2:开发者_如何学C

data2Id| DATA
----------------
 int   | string
 int   | string

I would then do a SELECT with an INNER JOIN to get the DATA in data2 with the correct dataId. Then, I would send the found strings in a List

Option 2.

data1:

dataId | DATA
----------------
 int   | XML
 int   | XML
 ...   | ...

And the XML would look like that:

<DATA>string</DATA>
<DATA>string</DATA>
<DATA>string</DATA>
<DATA>string</DATA>

I would then SELECT the right DATA with the wanted dataId. Then I would send the XML to the client to parse it.

Does sending a huge list of string trough the WCF to the client would be more or less efficient then sending an XML and parse it client side?


I suppose you always want to do your best to minimise the amount of data going over the wire (within reason of course)

You need to weigh up the pros and cons of filtering the data on the server (and sending less data over the wire) and filtering the data on the client, which would give you more flexibility (but at a cost as it takes time to send the data over the wire)


Your question really boils down to "Is it more expensive to send more data or transmit multiple queries + result sets?". Each new query results in another round trip, which is generally a bad thing, but then, so is returning 10,000 rows if you only need 1,000 of them. The answer really depends on how much of the data you're accessing, and how frequently.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜