Telerik blogs

Databases can grow to be very complex, spanning hundreds of tables over multiple logically independent schemata. Handling such a database in a single Domain Model could be a troublesome and not very pleasant task. Such scenario would be more easily manageable and cleaner if you could use separate models for the various logical parts of your database. Telerik Data Access allows you to do just that – you can have multiple Domain Models targeting the same database via a single connection string. In this blog post we will explain to you how Telerik Data Access handles such situation and how you need to configure your models for it.

How Does It Work

Each Telerik Data Access model has its own metadata which describes it. This metadata is cached once the model is initialized so that it ca be reused by the Telerik Data Access Runtime when the model is further instantiated. The key which is used to identify the cached metadata is based on the connection string used by the model.

This means that two models targeting different parts of a single database via the same connection string will have the same cache key for their metadata. When an instance of the first model is created, its metadata will be cached. When the second model is instantiated the already cached metadata will be used. This could pose a problem as the metadata of the first model does not contain any information about the second model. To avoid such issue Telerik Data Access will merge the metadata of the two models, if they are configured correctly, allowing you to use multiple models with the same connection string. Doing so is more simple than you might expect. Lets see how.

Configuring Domain Models to Merge their Metadata

In order to merge the metadata of models using the same connection string, Telerik Data Access has only one requirement - the models should be located in the same namespace. The models can still be in different projects, but their context classes (the ones deriving from OpenAccessContext) should share the same namespace. The persistent classes themselves on the other hand can be in different namespaces.

For example if you have two Domain Models in your solution – one for the HumanResources schema of AdventureWorks and one for the Production schema.

You would need to set the namespaces of both models to match. This can be done from the properties window of the Visual Designer – just click on the designer surface and press F4 on the keyboard or use the context menu to open it.

As you can see configuring your models so that their metadata can be merged is so simple that you may be already using this feature without knowing.

The Q2 2014 release is nearing. Are you interested in what will Telerik Data Access bring to the table for it? Check out our blog next week when we will talk about one of our new, highly requested features.

570x100-telerik-blogs

About the Author

Kristian Nikolov

Kristian Nikolov is Support Officer.

Comments

Comments are disabled in preview mode.