Ticket T279365
Visible to All Users
Duplicate

Create Dynamic Database Fields at runtime in XAF

created 10 years ago

I need a solution for adding some fields at runtime and make a one to many relationship.

As an example:

I´ll define a Table named Products static with defined fields:

1.) Name
2.) Description

Name is a unique Key.

Now at runtime, the user should Input new products. But for any new product, there are different Kind of properteis. They must defined by the user itself.

User define a product named A.

Product A has properties

weight
color

User define a product B

Product B has propertiies

size
lifetime

So it should be possible that the user can define the properties in a separate Parameter Table with Name, Type, perhaps limitations (min/max), can associate theses to different Products and can use theses als o in a imput mask for editing with Validation.

I know, everything is possible with XAF :-) but perhaps you have some examples, how i can do that.

Answers approved by DevExpress Support

created 10 years ago (modified 10 years ago)

Hello Thomas,

Yes, everything is possible. For this task, you can create a custom user interface, probably based on a persistent Parameter business class with Name, Type and other attributes.
I elaborated more on the API that will be required for accomplishing this task in the Creating Users Defined Fields at Runtime ticket. While we do not have a ready example for this, I hope you will find this information helpful.
Finally, I want to say that I saw several other customers doing a similar thing in their projects: they stored some configuration data in the database tables and then established runtime associations or added simple scalar fields as per How to customize an XPO business model at runtime (Example).

    Show previous comments (5)

      Hi Dennis,
      additional Info: Perhaps, i made the solution to complex.
      In the final Database where the users enter value, it´s not necessary that the fields have the definted Format (string, date …) Her it may be possible, that the Format is allways 'String'. But by Insert or edit theses values, i Need the possibility to Display These in differnt Formats in the UI and also use different Validation rules.
      Is it possible to define the value-property as string, but Change the type by using this in a view?

      Dennis Garavsky (DevExpress) 9 years ago

        Thanks for providing additional information on what you want to build. That's an interesting and challenging task as I see. Bearing in mind that by "component" you mean a new business type that requires a standard CRUD UI, support for system modules like security, validation, appearance, etc., it seems feasible to accomplish this task with the Types Info API suggested earlier. In the simplest case, you can define a base component class statically in your library and then dynamically add required properties to it based on your user metadata. In a more complex case, you can generate required business classes dynamically using the AssemblyBuilder.

        >>Is it possible to define the value-property as string, but Change the type by using this in a view?
        There is no built-in functionality for this at the moment as built-in XAF editors are supposed to work for a concrete type, e.g., string, integer, and are not supposed to be changed at runtime. Technically, you can create custom editors for the System.String that would use different controls based on additional metadata info, but that may be too complicated, not to mention that there may be possible implications with the database saving.

          Tx Dennis,
          i´ll try ist and give you informations about the solution

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.