Multiple FluentMetadataSource for a single context

3 posts, 0 answers
  1. Christophla
    Christophla avatar
    28 posts
    Member since:
    Jul 2012

    Posted 07 Mar 2012 Link to this post

    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. Christophla
    Christophla avatar
    28 posts
    Member since:
    Jul 2012

    Posted 07 Mar 2012 Link to this post

    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);

  3. DevCraft banner
  4. Alexander
    Alexander avatar
    727 posts

    Posted 09 Mar 2012 Link to this post

    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).

    the Telerik team
    Telerik OpenAccess ORM Q1 2012 release is here! Check out what's new or download a free trial >>
Back to Top