简体   繁体   English

将数据从数据库传输到服务器再传输到客户端的最有效方法是什么?

[英]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 data2DATA 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.

相关问题 在服务器和客户端之间发送查询结果的最有效方法是什么 - What is the most efficient way to send query results between Server and Client 检查客户端应用程序发送的数据是否来自多租户应用程序中的同一租户的最有效方法是什么? - What is the most efficient way to check if data that the client app send is from the same tenant in multi-tenant app? 在我的情况下,通过JavaScript从EntityFramework数据库中获取数据的最佳和最有效的方法是什么? - What is the best and most efficient way to get data by JavaScript from EntityFramework database in my case? 从DataReader检索数据的最有效方法是什么? - What is the most efficient way of retrieving data from a DataReader? 判断代码是在客户端还是在服务器上执行的最简单,最有效的方法是什么? - What's the simplest & most efficient way of telling if your code is executing on the client or the server? 从本地SQL Server数据库检索数据的最直接方法是什么? - What is the most straightforward way to retrieve data from a local SQL Server database? 将WPF应用程序与SQL Server数据库一起部署的最有效方法是什么? - What is the most efficient way to deploy a WPF application together with a SQL Server database? 从流中读取数据的最有效方式 - Most efficient way of reading data from a stream 使用SqlDataReader(C#)从SQL Server读取许多字节的最有效方法是什么 - What is the most efficient way to read many bytes from SQL Server using SqlDataReader (C#) 从MySQL服务器删除多个记录的最有效方法是什么? - What's the most efficient way of deleting multiple records from a MySQL server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM