Common Cloud and Software as a Service (SAAS) applications, typically require the use of data from multiple sources. Accessing data from multiples sources can be complicated.
This blog will discuss how accessing data from multiple sources can be simplified using an open source Object Relational Mapper (ORM) as part of the multi-tenant application. An example will be provided using the Open-Source Entity Framework (EF) ORM and a multi-tenant application will be simulated using a windows forms application.
SaaS is a software distribution model in which applications are hosted by a vendor or service provider and made available to customers over a network, typically the Internet.
Software Multitenancy refers to a software architecture in which a single instance of a software runs on a server and serves multiple tenants. A tenant is a group of users who share a common access with specific privileges to the software instance. With a multitenant architecture, a software application is designed to provide every tenant a dedicated share of the instance including its data, configuration, user management, tenant individual functionality and non-functional properties. Multitenancy contrasts with multi-instance architectures, where separate software instances operate on behalf of different tenants.
One method to support application in a multi-tenant application is to host the user specific data on disparate servers for redundancy or security reasons. Such a method is commonly referred as the “Isolated” hosting method.
Object-relational mapping (ORM) is a mechanism that makes it possible to address, access and manipulate objects without having to consider how those objects relate to their data sources. ORM lets programmers maintain a consistent view of objects over time. EF is a common ORM used by developers.
Entity Framework is an object-relational mapper (ORM) that reduces the impedance mismatch between the object-oriented world of .NET Framework developers and the world of relational databases. It enables developers to primarily interact with an application’s conceptual model, using familiar object-oriented techniques. In Entity Framework you can work with data in the form of domain-specific objects and properties, such as customers and customer addresses, without having to concern one’s self with the underlying database tables and columns where this data is stored. Developers can issue data access operations against the conceptual model, and Entity Framework translates the operations into relational database actions.
Put it all together
A rudimentary application was created to demonstrate how data in disparate databases can be managed in one application using EF. Each database has the same schema.
In the example below, a user can choose both a source and a target database in which to copy data. In this case, data from one data source will be copied to the other data source.
A User Interface was created to allow a user to select source and target databases.
Below is the user interface wherein the user selects both a source and a target database:
Data in each list box above was populated from the Connection String section of the App Config file.
The following code was used to populate each listbox:
Clicking the Copy Button will initiate a data copy between source and target databases.
Below is the code that handles the Click Event from clicking the Copy Button, and subsequently initiates the copy of data from the source to the target database:
Below is the code that does the actual copy:
This blog discussed SAAS, Software Multitenancy, ORM and Entity Framework, and presented a simple example of a simulated Multi-Tenant application using entity framework to access data, in this case copy data from 2 separate databases. It also discussed how accessing data from multiple sources can be simplified using an open source Object Relational Mapper (ORM) as part of the multi-tenant application, which leads to reduced development time in business environments.