Is it Possible to Query Multiple Databases with WCF Data Services?

一个人想着一个人 提交于 2019-12-08 02:16:52

问题


I have data being inserted into multiple databases with the same schema. The multiple databases exist for performance reasons.

I need to create a WCF service that a client can use to query the databases. However from the client's point of view, there is only 1 database. By this I mean when a client performs a query, it should query all databases and return the combined results.

I also need to provide the flexibility for the client to define its own queries. Therefore I am looking into WCF Data Services, which provides the very nice functionality for client specified queries.

So far, it seems that a DataService can only make a query to a single database. I found no override that would allow me to dispatch queries to multiple databases.

Does anyone know if it is possible for a WCF Data Service to query against multiple databases with the same schema?


回答1:


I think you have to write a facade service that will dispatch the query to the underlying - either in sequence or in parallel. You will typically create the facade in such a way that the WCF Data Service uses the Reflection Provider and you can use LINQ to SQL or Entity Framework for the underlying databases.

How to: Create a Data Service Using the Reflection Provider (WCF Data Services): http://msdn.microsoft.com/en-us/library/dd728281.aspx

HTH,

--larsw




回答2:


I posted the question on the MSDN forums and found out that it will require a lot of effort.

It involves creating your own data service provider, which is tricky and can be a lot of work. On top of that merging results with sorting + paging will be a task that is far too complicated and risky for what I am willing to do. For example, how do I query multiple databases for page 1000 sorted by the Name column? I would essentially have to query all data from all databases, sort by Name, then select the 1000th page.




回答3:


Seems like you need to use a different approach. I'm talking about Distributed Caches, such as Oracle Coherence or NCache. The structure is really transparent - you interact with in-memory database that is synchronized with your "backing map" - one or more databases.

There are a lot of interesting features in such caches. for example you can change a store strategy or build a backing map with a different databases (MS SQL, Oracle etc.)



来源:https://stackoverflow.com/questions/4659397/is-it-possible-to-query-multiple-databases-with-wcf-data-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!