Base solution for your next web application
Open Closed

IExtendableObject Interface for Entities #4690


User avatar
0
BobIngham created

Is the are any sample code for this functionality beyond the few lines in the documentation for Entities?


12 Answer(s)
  • User Avatar
    0
    vladsd created

    Have you seen this link: <a class="postlink" href="https://www.aspnetzero.com/Documents/Extending-Existing-Entities">https://www.aspnetzero.com/Documents/Ex ... g-Entities</a>

  • User Avatar
    0
    BobIngham created

    Thanks, Vlad. Yes I've seen that. My thoughts were to use the

    IExtendableObject
    

    properties to hold arrays of key-value data against any entity and write a generic angular component to allow the user to add attributes. Thus, I would have an Attribute class containing generic data types and data input rules. For example an attribute called "Name" would be a string with definitions for max/min, required etc; "Age" would be a number with definitions for max/min/required etc. The admin user defines the attributes which may be used to describe an entity and these are used in data input forms. The user adds an item to a form array, a drop down would allow selection of an attribute, the Attribute object would dictate the input type and the results would be saved as key-value pairs in the

    ExtensionData
    

    field. Zero has get and set operations for this data and JSON functions in SQL Server would allow easy querying. In this way i would reduce requests from Tenants for extra or different data fields. They simply define an entity and then describe this entity through a series of attributes. The entity may be a person, a shop, a location or any other object. I was hoping for some simple get and set examples beyond the few lines of description in the Entity documentation.

  • User Avatar
    0
    ismcagdas created
    Support Team

    What about this one <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/test/Abp.Tests/Domain/Entities/ExtendableObject_Tests.cs">https://github.com/aspnetboilerplate/as ... t_Tests.cs</a> ?

  • User Avatar
    0
    alper created
    Support Team

    actually the feature is very simple! stores some data in a specific property and retrieves it with some shortcut methods. what you want to achieve is a use-case implementation. so it's expected to be implemented the use-case solutions in the end-product. thanks for your valuable feature request.

  • User Avatar
    0
    BobIngham created

    @alper, you are correct, what I am planning is a use-case implementation. I bet you are also correct in assuming I am being lazy in looking for examples of the same use-case implementation! @ismcagdas, thanks, that's exactly what I was looking for.

  • User Avatar
    0
    BobIngham created

    @ismcagdas - the tests gave me a lot of pointers, thanks.
    I read a third party database, get the relevant row and iterate through the columns in the database using sys.columns and, if the cell has a value I save it into a dictionary. I serialise the dictionary and pass it back to Zero where it is deserialised and then, using a foreach loop, I use entity.SetData() for each key-value-pair. I now have a set of entities in Zero and I want to get the data from ExtensionData. Each entity has a different number of kvp's and each may have different values for keys. My question is:

    Is there any foreach mechanism to read through each KVP in the IExtensibleObject interface or am I faced with casting json back to a dymanic object and iterating through that (which kind of negates the whole point of IExtensibleObject?

  • User Avatar
    0
    BobIngham created

    @ismcagdas - perhaps an easier question would be to ask: Once I have ExtensionData set as follows,

    {"DataProviderId":"653","DateOfBirth":"03/02/1971 00:00:00"}
    

    how the hell do I iterate over it in Angular?

    I have tried pipes and Object.keys but I am getting nothing meaningful.

    Is there any code examples of using IExtendableObject in Angular or should I revert to using plain JSON saved in an nvarchar(max) column?

  • User Avatar
    0
    ismcagdas created
    Support Team

    @BobIngham as far as I know it is not directly possible. You can iterate using raw javascript and add items to a list, then iterate using angular.

    for(var key in myObject){ 
    	console.log(key +":"+ myObject[key]);
    }
    
  • User Avatar
    0
    BobIngham created

    @ismcagdas - thanks for your time on this. I will come back to the problem later but I'm beginning to think that the ability to get and set values on the server give me little advantage. I will take a look at mapping to a typescript interface in Angular later but all-in-all I think a simple nvarchar(max) with raw json will give me better results. Again, thanks for your efforts.

  • User Avatar
    0
    vladsd created

    @ismcagdas - another good case for using nosql database where building app which uses unstructured data a way to go, which is pretty much every app built for the web this days. personally, I think a lot of business is lost for zero framework due to lack of nosql database support.

  • User Avatar
    0
    alper created
    Support Team

    I agree with you @vladsd but AspNet Zero uses Entity Framework to handle different database system. And Entity Frameowork does it's job very good. On the other hand Entity Framework is an ORM and NoSQL thing is not ORM-ish... You have to implement their APIs for each of them. It requires extra extra work to support different systems like MongoDB, Cassandra, RavenDB, CouchDB etc... And some fundamental features like transactions, data filters will not work for them. So it's being more complicated for a base framework to spread widely. There must be some limitations to do your existing work best. The mission is not covering all developers but give best to the existing ones :)

  • User Avatar
    0
    vladsd created

    @alper - I understand your point and do not see MSFT investing into EF support for nosql, even so on their website its says that EF supports CosmoDB nosql! - Go figure.

    There are other efforts to map EF and Mongo DB, see this thread as an example.

    #3998@aad0d63b-904e-47b5-b115-2ee2014e203b