Print Page | Close Window

Splitting entity in multiple databases

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2983
Printed Date: 04-May-2025 at 1:20am


Topic: Splitting entity in multiple databases
Posted By: s_tristan
Subject: Splitting entity in multiple databases
Date Posted: 28-Sep-2011 at 6:27am
We are developing a SaaS application that contains:
  • one shared nonsecured database with reference data (countries, regions, cities etc.)
  • one separate database per each customer of application
So there are a simply entity - Address with such properties:
  • Zip (string)
  • Country (reference to Country)
  • Region (reference to Region)
  • City(reference to City)
  • Address line (string)
We want to store Address entity in the customer database, while the references (Country, Region, City) are in the shared database.

How to implement this scenario with DF?



Replies:
Posted By: ting
Date Posted: 28-Sep-2011 at 4:18pm
Hi Tristan,

You would define a model (EDMX) for the customer database and another model for the shared database. A DevForce EntityManager can work with multiple models as shown in these examples:
http://drc.ideablade.com/xwiki/bin/view/Documentation/many-models-per-manager - http://drc.ideablade.com/xwiki/bin/view/Documentation/many-models-per-manager
http://drc.ideablade.com/xwiki/bin/view/Documentation/code-sample-query-multiple-models - http://drc.ideablade.com/xwiki/bin/view/Documentation/code-sample-query-multiple-models
http://drc.ideablade.com/xwiki/bin/view/Documentation/code-sample-working-multiple-models - http://drc.ideablade.com/xwiki/bin/view/Documentation/code-sample-working-multiple-models

By default, there won't be navigation properties that navigate from one model to another (DevForce/EF doesn't know about these relationships), but you could write these yourself in the partial classes.

However, I'd recommend that you use a repository pattern in a different assembly to navigate across models. A repository pattern in general is a good idea, and it will save you from having to deal with any circular reference issues if you want to navigate bidirectionally between the models.

For example, one of the methods in the repository might look like this:
country = Repository.GetCountry(address);




Print Page | Close Window