Dynamic database and models changes.

2 posts, 0 answers
  1. E
    E avatar
    2 posts
    Member since:
    Sep 2012

    Posted 10 Sep 2012 Link to this post

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

  2. PetarP
    PetarP avatar
    754 posts

    Posted 13 Sep 2012 Link to this post

    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.

    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
Back to Top