This is a migrated thread and some comments may be shown as answers.

Multiple FluentMetadataSource for a single context

2 Answers 58 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Christophla
Top achievements
Rank 1
Christophla asked on 08 Mar 2012, 04:07 AM
I am in the process of creating a security framework that resides in its own assembly with its own FluentMetatdataSource. I would like to be able to register the framework with an existing database context, but am unable to determine how / if there is a way to do this...

Currently, the OpenAccessContext only supports a single datasource (as far as I can tell):

var metadata1 = new AppFluentDataSource();
var metadata2 = new SecurityMetaDataSource();
 
var context = new OpenAccessContext(_connectionString, configuration, metadata1);

Currently, I can only reference the object mappings defined in the registered datasource - the objects in the non-registered datasource throw an object reference error:

at Telerik.OpenAccess.SPI.Backends.ThrowException(Exception e)
at OpenAccessRuntime.ExceptionWrapper.Throw()
at OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.handleException(Exception x)
at OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.makePersistent(Object o)
at OpenAccessRuntime.DataObjects.UnsynchronizedPMProxy.makePersistent(Object o)
at OpenAccessRuntime.ObjectScope.Add(Object pc)
at Telerik.OpenAccess.OpenAccessContextBase.Add(Object entity)


Am I missing something?


2 Answers, 1 is accepted

Sort by
0
Christophla
Top achievements
Rank 1
answered on 08 Mar 2012, 04:24 AM
It looks like I solved my own problem with the aggregate datasource:

var testFluentDataSource = new TestFluentDataSource();
var securityMetaDataSource = new SecurityMetaDataSource();
 
var aggregateMetadataSource = new AggregateMetadataSource(testFluentDataSource, securityMetaDataSource, AggregationOptions.Late);
MetadataContainer metadataContainer = aggregateMetadataSource.GetModel();
 
_context = new OpenAccessContext(_connectionString, configuration, metadataContainer);



0
Alexander
Telerik team
answered on 09 Mar 2012, 11:48 AM
Hi Christophla,

This is indeed the correct solution. Just have in mind that the metadata is cached the first time you instantiate a context, so the metadata aggregation should be performed before any context instances are created with this connection string (the connection string is the key to the cached metadata).

Greetings,
Alexander
the Telerik team
Telerik OpenAccess ORM Q1 2012 release is here! Check out what's new or download a free trial >>
Tags
General Discussions
Asked by
Christophla
Top achievements
Rank 1
Answers by
Christophla
Top achievements
Rank 1
Alexander
Telerik team
Share this question
or