[英]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: 我想知道在这两个选项之间将数据从数据库传输到WCF服务再传输到客户端的最佳方法是什么:
Option 1. I have two tables in my database, "data1" and "data2". 选项1.我的数据库中有两个表“ data1”和“ data2”。 The to table are linked by "data2Id". 到表通过“ data2Id”链接。 data2Id is not unique and can be linked to more then one DATA. data2Id不是唯一的,可以链接到多个DATA。
data1:
dataId | data2Id
----------------
int | int
int | int
... | ...
data2:
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
. 然后,我将使用INNER JOIN
进行SELECT
以获得具有正确dataId
data2
的DATA
。 Then, I would send the found strings in a List 然后,我会将找到的字符串发送到列表中
Option 2. 选项2。
data1:
dataId | DATA
----------------
int | XML
int | XML
... | ...
And the XML would look like that: XML看起来像这样:
<DATA>string</DATA>
<DATA>string</DATA>
<DATA>string</DATA>
<DATA>string</DATA>
I would then SELECT
the right DATA with the wanted dataId. 然后,我将使用所需的dataId SELECT
正确的数据。 Then I would send the XML to the client to parse it. 然后,我会将XML发送给客户端以对其进行解析。
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? 通过WCF向客户端发送大量字符串会比发送XML并在客户端进行解析来提高效率吗?
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. 每个新查询都会导致另一次往返,这通常是一件坏事,但是如果只需要其中的1000行,那么返回10,000行。 The answer really depends on how much of the data you're accessing, and how frequently. 答案确实取决于您正在访问的数据量和频率。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.