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

Dynamic database and models changes.

1 Answer 78 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.
E
Top achievements
Rank 1
E asked on 10 Sep 2012, 01:30 PM
Hi,
Please, i really need your help.
I wonder what is the best way with Telerik ORM to achive my needs.

I need to implement a multitenancy  on my database for this i need to create a new table per tenant to extend default table. This should be handled in runtime as well as net strong types. So lets say tenant wants to extend Products table, he sends a new fields to my service, im creating a new dll with new strong clr type, CustomProducts.dll created it inherited from Product persistent type. Then i need to map this object using Fluent functionality of Telerik ORM, i didnt found any other way but creating a new context, and sending a new metadata in constructor. So i need to construct a new FluentMetadataSource instance and override a PrepareMapping() with my new mapping for new type. So to create a new table or work with it using my new clr type and map it, i need to do something like this .

Type newMetaDataType = System.Reflection.Assembly.LoadFrom(name + ".dll").GetTypes().FirstOrDefault(x => x.Name == name);
object newMetaDataInstance = Activator.CreateInstance(newMetaDataType);
var model = (newMetaDataInstance as Telerik.OpenAccess.Metadata.Fluent.FluentMetadataSource).GetModel();
 using (var context = new FluentModel1Context(model))
  {
      context.UpdateSchema();
   }
So generally i need to store a 2 dlls with clr types and with mapping and load it runtime and use. I read about artifical types and i see that im doing very similar things here. But i didnt found a way artifical types to inherit from persistance type.
My problem is that when im starting to use context here it throws an error, It is only happens when im loading FluentMetadataSource from DLL. How i can fix this problem to map my new type via reflection, or is there any other way to achive my goal. All i need is to create a new strong type and map it in runtime, to create a new table and use it .

1 Answer, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 13 Sep 2012, 12:22 PM
Hi E,

 Indeed when using the artificial types you will not be able to have a real clr type at hand. The only way would be to have the type in place and extend it further with artificial properties. Be aware that those properties will be accessible only via property descriptors and not as a real clr properties.
I am afraid that if you would like to add a new type during runtime without restarting the application the only way would be to use the artificial types which apparently does not work for you.

Regards,
Petar
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
E
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Share this question
or