locked
Use related entity field in DataField of DynamicControl RRS feed

  • Question

  • User539648229 posted

    Hi

    Is there any way to do something like this:

    <asp:DynamicControl runat="server" DataField="Supplier.Title" ID="Title" />

    Thanks

    Sunday, January 17, 2016 11:31 AM

Answers

  • User-330204900 posted

    no again Ali, that will not work with DD and the current EF Data Source.

    you can only get this to work by adding a Computed column to the database (and only for simple situations) and then you need to add a

    [Display(AutoGenerateField = true)] to that column in you model/metadata.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 19, 2016 9:26 AM

All replies

  • User-271186128 posted

    Hi IranianCuriousBoy,

    You could create a temporary class which contains all of the fields you want to display, then use it to bind the data.

    For example, the Student (StudentID, StudentName) and StudentAddress (StudentID, Address, City) contains One-to-One relationship, then you could create a StudentAddressModel class, which contains the following fields: StudentID, StudentName, AddResss and City. Then, you could use the temporary class to bind the DynamicControl.

    Best regards,
    Dillion

    Monday, January 18, 2016 2:55 AM
  • User-330204900 posted

    Hi Ali, you cant reach across entities like that sorry you can only supply the field names of the current entity, I get around this my self by using Computed columns for simple cases.

    Monday, January 18, 2016 12:29 PM
  • User539648229 posted

    Hi

    I think i must use the following in the model:

            [NotMapped]
            public string SupplierTitle
            { get { return Supplier.Title; } }

    or the following in the Data Control:

    <%#: Item.Supplier.Title %>

    Actually I knew them but I thought there might be some smart DD form of using navigation properties because the frequency of using it is high.

    Thanks anyway

    Tuesday, January 19, 2016 7:25 AM
  • User-330204900 posted

    no again Ali, that will not work with DD and the current EF Data Source.

    you can only get this to work by adding a Computed column to the database (and only for simple situations) and then you need to add a

    [Display(AutoGenerateField = true)] to that column in you model/metadata.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 19, 2016 9:26 AM