开发者

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

开发者 https://www.devze.com 2023-02-03 10:47 出处:网络
I have data being inserted into multiple databases with the same schema. The multiple databases exist for performance reasons.

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. Ho开发者_JAVA技巧wever 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?


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


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.


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.)

0

精彩评论

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

关注公众号