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

Map configuration to another table

3 Answers 59 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
stuart
Top achievements
Rank 1
stuart asked on 31 Jul 2012, 11:50 PM
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);

3 Answers, 1 is accepted

Sort by
0
Zoran
Telerik team
answered on 06 Aug 2012, 06:51 AM
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!
0
stuart
Top achievements
Rank 1
answered on 06 Aug 2012, 04:57 PM
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.
0
Zoran
Telerik team
answered on 09 Aug 2012, 05:51 AM
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!
Tags
Data Access Free Edition
Asked by
stuart
Top achievements
Rank 1
Answers by
Zoran
Telerik team
stuart
Top achievements
Rank 1
Share this question
or