Map configuration to another table

4 posts, 0 answers
  1. stuart
    stuart avatar
    8 posts
    Member since:
    Oct 2012

    Posted 31 Jul 2012 Link to this post

    I am using the Fluent API to dynamically query my SQL server database. The reason I'm doing this as opposed to using the domain model generator is that I want to set the data table at run-time. I've noticed that if I instantiate a new instance of my context and change the table name, it does not update the table that's being queried after the first call. Is this being cached some how? I would like to instantiate my context several times within my session (not all at the same time), however, each time I want to change the name of the table that's being queried in my context, I see results from the original instance even through its been disposed as if it remembers the first table name I gave it. 

    protected override IList<MappingConfiguration> PrepareMapping()
           {
               List<MappingConfiguration> configurations = new List<MappingConfiguration>();
     
               MappingConfiguration<Model> configuration = new MappingConfiguration<Model>();
               configuration.MapType()
                   .WithDataAccessKind(Telerik.OpenAccess.DataAccessKind.ReadOnly)
                   .ToTable(tableName);

  2. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 06 Aug 2012 Link to this post

    Hello Stuart,

     Yes, the OpenAccess runtime metadata is being cached and the cache key is the connection id you are using. What you can do in order to instantiate a context using the new metadata, is to have an additional connection string entry in your configuration file, which might point to the very same database as the original connection string, but under a different connection id. Then you can instantiate the new context using the new connection id. This means that you should have as many connection string entries as different table names you would like to use for a single entity type.

    Greetings,
    Zoran
    the Telerik team
    Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
  3. DevCraft banner
  4. stuart
    stuart avatar
    8 posts
    Member since:
    Oct 2012

    Posted 06 Aug 2012 Link to this post

    I understand that this is a bad practice, but is there a way to disable caching of the metadata all together? If not, can I change my cache key? It would be unreasonable to have a connection string for each table as there are hundreds of tables. This is an internal website so I'm not as concerned about performance.
  5. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 09 Aug 2012 Link to this post

    Hi Stuard,

     No, unfortunately it is not possible to disable Metadata caching, but there is another approach we have recently added to the product for extending the metadata. Please have a look in the following documentation article and try implementing the approach there, if it is not possible for you to have your metadata calculated on bigger intervals than at the moment and use fewer connection strings.

    All the best,
    Zoran
    the Telerik team
    Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
Back to Top