Home  /  Questions  /  Question



67   95.8
Sep 17, 2013


Does the Spark platform support connecting to multiple databases?

In the Spark platform how can I connect to multiple database to perform CRUD operations?



508   99.9
Sep 17, 2013
Parity Bit: 

Yes, Spark makes it incredibly easy to connect to multiple databases.

It is explained in the documentation, but let's look at the Art Shop solution as an example. It has two projects: Art.Web and Art.DomainArt.Web is the MVC application and Art.Domain contains the domain objects and data access code to the Art database. 

Suppose you need to access an another database called Inventory which maintains the availability of products. 
In Spark you would simply create a new project, say, Inv.Domain which contains the domain objects and data access code to the Inventory database. 

In your code you would access these databases like so: 

ArtContext.Artists.Update(artist);

InvContext.Sales.Update(sale);
Here artist is a domain object related to the Art database and sale is a domain object related to the Inventory database.  

You could even wrap these UPDATE statements inside a distributed transaction using the UnitOfWorkDistributed object which is part of the Spark platform (this is the Unit of Work design pattern).

As you can see Spark makes it very easy to access multiple databases. 

I hope this helps. 
Jack