locked
Entity Framework and dynamic model extension/adding new types at runtime RRS feed

  • Question

  • Hello!

    Currently in our application we are developing a core functionality of an "order system" with a core objects model with objects like "User", "Order", "Product" so a classic example of a simple object model with relations between the objects.

    Now in our application it is possible for other developers to extend the functionality to extent the application tp their needs. So somebody might decide to extend our "order system" with a completely new functionality like for example "work time recording". So new classed might be introtuced like a "TimeBooking" where the "User" object from the core applications model hose 0-many time bookings and so on and so forth. (Obviously this relation would be unidirectional since the assembly that defines the "User" object cannot know anything of "TimeBooking" at compile time).

    These extensions are in separate C# assemblies that can be copy deployed into the applications AddIns directory and are loaded upon starting the application.

    The way we do this now is that our entire DB-Model operates on a meta level. So a new type of objects is just a row in a TypeTable and the attributes of this type are just new rows in an AttributeTable and so on. Then for all those meta tables there are of course value tables where to actual values of objects are so when an object is loaded its property values are picked up from across those tables and then the object is constructed in this way.

    Now we are thinking whether we simplify our application and focus on business logic by using Entity Framework. One of the main points is though that this sort of dynamic extensibility of our business model is a very important feature. Is the scenario that I described above something that can easily be achieved with the Entity Framework?

    Monday, March 30, 2015 7:22 PM

Answers

  • Hi JoWi85,

    -->Is the scenario that I described above something that can easily be achieved with the Entity Framework?

    As far as I know, it is OK, Entity Framework (EF) is an object-relational mapper that enables us to work with relational data using domain-specific objects. there is no conflicts with your dynamic extensibility. you could get the data by EF, then handle the data by using your extensibilities.

    You could learn to how to use EF from here: https://msdn.microsoft.com/en-gb/data/ef.aspx?f=255&MSPPError=-2147217396

    Best regards,
    Youjun Tang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Fred Bao Tuesday, April 7, 2015 5:48 AM
    • Marked as answer by Fred Bao Saturday, April 25, 2015 2:13 AM
    Wednesday, April 1, 2015 7:27 AM

All replies

  • Hi JoWi85,

    -->Is the scenario that I described above something that can easily be achieved with the Entity Framework?

    As far as I know, it is OK, Entity Framework (EF) is an object-relational mapper that enables us to work with relational data using domain-specific objects. there is no conflicts with your dynamic extensibility. you could get the data by EF, then handle the data by using your extensibilities.

    You could learn to how to use EF from here: https://msdn.microsoft.com/en-gb/data/ef.aspx?f=255&MSPPError=-2147217396

    Best regards,
    Youjun Tang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Fred Bao Tuesday, April 7, 2015 5:48 AM
    • Marked as answer by Fred Bao Saturday, April 25, 2015 2:13 AM
    Wednesday, April 1, 2015 7:27 AM
  • Thanks you for your input. Adding EF as the actual data access layer and then adding my logic on top was something that I hadn't really thought about.
    Friday, April 3, 2015 7:47 AM
  • Hello JoWi85.

    For your case, I suggest that you could have a try with the Code First approach and use automatic migration:

    https://msdn.microsoft.com/en-us/data/jj554735.aspx?f=255&MSPPError=-2147217396

    It could detect if the model is changed, if changed, it then would save these changes to database as adding a new entity class or a entity class property.

    Regards,

    Fred.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, April 7, 2015 5:48 AM