locked
Displaying Complex Types in a Dynamic Data Web Site RRS feed

  • Question

  • User1737159284 posted

    I have created a Complex Type for my Address objects in my model.

    How do I get these addresses to be displayed in the details view?

    Do I need to create a Field Template or Entity Template for the Address Complex Type?

    Wednesday, March 10, 2010 9:43 AM

Answers

  • User1641955678 posted

    Note that if you're really fearless, there are some things that you can try.  But they could involve a fair bit of work, and may not lead to success.

    First idea is to implement your own MetaModel/MetaTable, which could let you return your own additional columns.  Steve has a post on something like this.

    The second idea is to implement a custom version of the EFDataModelProvider so that it doesn't ignore Complex props.  But you really wouldn't want to re-implement this from scratch, so we'd need to find a way to put out the current implementation as a sample (not sure how feasible that is).

    Again, not things I would normally recommend try it unless you're really driven :)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 10, 2010 6:48 PM
  • User-644412204 posted

    Hi,

    I have bumped into this issue of complex types as well and sent a feedback to the DD team. The response was as follows:

    'As of now Dynamic data doesn't support complex types. WebForms and Dynamic Data do not have support for data binding complex types. If you are using Entity Framework for the complex types the EntityDataSource has some support for flattening the object (making top level aliases for each of the complex properties which would allow doing data binding with data controls, so you should be able to make this work with the EntityDataSource and data controls. Dynamic Data does not support complex types at this time, mainly because Web Forms does not support the scenario (other than in the case EntityDataSource flattens objects). We are considering better binding support for future versions of Web Forms.'
     
    Not sure how to create those top level aliases or where ?
    Anyways, I managed to move forward with my dynamic data app by using BoundFields or TemplateFields inside my databound controls and setting their DataField property to the complex property name, for example Address.Country . This cannot be done using DynamicFields and DynamicControls
    
    Note that the complex type issues seems to also applies to accessing related entities (assuming they are loaded using Include), for example Customer.Name within a databound control that displays SalesOrderHeader data. That makes sense since in this case, Customer.Name is indeed a complex property.
     
    Yacine
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 11, 2010 7:15 AM

All replies

  • User-330204900 posted

    Hi Mr Dave M, that is a good question, I knew about the complex type but I hadn't thought about it. I'll see if I can find anything about it.

    Wednesday, March 10, 2010 1:58 PM
  • User1641955678 posted

    Complex Types is an Entity Framework concept which Dynamic Data does not directly support currently.  However, I think it should be possible to create a field template for it.  You'd just need to name the field template after the type (.e.g Address.ascx).  Then in your field template, 'FieldValue' should evaluate to your address object.  You can then cast it and display it the way you want.

    Note that I have not tried this, so please let us know how that works.

    thanks,
    David

    Wednesday, March 10, 2010 2:48 PM
  • User1737159284 posted

    Thanks guys, I will have a look at this tonight and get a post on my findings.

    Wednesday, March 10, 2010 4:01 PM
  • User1737159284 posted

    OK, So on first dive into this issue I have found that the Table that is created to bind the Dynamic Controls to does not contain any columns for the Address properties.

    Complex Types


    Still looking into it but if this rattles any cages let me know.



    Wednesday, March 10, 2010 5:55 PM
  • User1641955678 posted

    Darn, you're right, the Dynamic Data DataModelProvider for EF indeed ignores those properties and does not create columns for them. :(  Note that techincally, the objects that are returned from queries should still contain those complex properties and you can get at them (e.g. with regular ASP.NET Eval()), but getting Dynamic Data involved in their handling might prove tricky.

    Maybe we need to think about what it would take to really support this in the next version of Dynamic Data.

    David

    Wednesday, March 10, 2010 6:14 PM
  • User1737159284 posted

    Yes I have an ASP.net Site already built with standard EntityDataSource controls and the Complex Types are represented just fine.

    I wanted to try and use Dynamic Data because of the extra functionality that it provides 'out of the box'.  

    I keep finding all these little issues that keep stopping us from fully implementing it.

    I love where Dynamic Data is headed and am glad to help out where I can.

    I will continue to persist as I don't like accepting defeat! Laughing

    Anyway, its late now so I will shelve this till tomorrow evening.


    Wednesday, March 10, 2010 6:36 PM
  • User1641955678 posted

    Note that if you're really fearless, there are some things that you can try.  But they could involve a fair bit of work, and may not lead to success.

    First idea is to implement your own MetaModel/MetaTable, which could let you return your own additional columns.  Steve has a post on something like this.

    The second idea is to implement a custom version of the EFDataModelProvider so that it doesn't ignore Complex props.  But you really wouldn't want to re-implement this from scratch, so we'd need to find a way to put out the current implementation as a sample (not sure how feasible that is).

    Again, not things I would normally recommend try it unless you're really driven :)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 10, 2010 6:48 PM
  • User1737159284 posted

    I will check out Steve's post. 

    If you want me to look at the current implementation of the EFDataModelProvider i'd be more than happy to.  What might take a while to sort out now is bound to save alot of other developers time in the future.


    Regards

    Dave

    Wednesday, March 10, 2010 6:55 PM
  • User-644412204 posted

    Hi,

    I have bumped into this issue of complex types as well and sent a feedback to the DD team. The response was as follows:

    'As of now Dynamic data doesn't support complex types. WebForms and Dynamic Data do not have support for data binding complex types. If you are using Entity Framework for the complex types the EntityDataSource has some support for flattening the object (making top level aliases for each of the complex properties which would allow doing data binding with data controls, so you should be able to make this work with the EntityDataSource and data controls. Dynamic Data does not support complex types at this time, mainly because Web Forms does not support the scenario (other than in the case EntityDataSource flattens objects). We are considering better binding support for future versions of Web Forms.'
     
    Not sure how to create those top level aliases or where ?
    Anyways, I managed to move forward with my dynamic data app by using BoundFields or TemplateFields inside my databound controls and setting their DataField property to the complex property name, for example Address.Country . This cannot be done using DynamicFields and DynamicControls
    
    Note that the complex type issues seems to also applies to accessing related entities (assuming they are loaded using Include), for example Customer.Name within a databound control that displays SalesOrderHeader data. That makes sense since in this case, Customer.Name is indeed a complex property.
     
    Yacine
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 11, 2010 7:15 AM
  • User1737159284 posted

    Thanks for the info Yacine.  

    Friday, March 12, 2010 6:13 PM
  • User-242633425 posted

    Hi,

    Is there any update on this? It's a real shame we can't use Dynamic Data to display Complex Type properties...

    Thanx,

    Kostas

    Wednesday, January 19, 2011 5:17 AM
  • User-330204900 posted

    Hi Kkara, I don't believe there is at the moment. 

    Wednesday, January 19, 2011 5:35 AM
  • User-833090171 posted

    Hello,

    Any news on this?

    Thanks.

    Thursday, January 23, 2014 9:09 PM
  • User-330204900 posted

    Still nothing I'm afraid with the fully scaffolded DD but there may be a way using Model Binding that was introduced for Web Froms in .Net 4.5 and enhanced in .Net 4.5.1

    Friday, January 24, 2014 5:42 AM
  • User-647007878 posted

    I have imported stored procedure usp_FullSearch into Dynamic Data 4.0 Web Site. I have specified the type of objects returned by the stored procedure. It is Complex Type usp_FullSearch_Result. Now i would like to call this SP from Web Service and then call Web Method from jQuery via ajax function. My question is which is the best option in the spirit Dynamic Data technology for Web Method return type. If i use my Complex Type jQuery ajax does not understand this type.

    My example (doesn't work):

    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public ObjectResult<usp_FullSearch_Result> FullSearch(string p_DataToFind)
    {
          using (AAEntities myEntity = new AAEntities())
          {
              return myEntity.usp_FullSearch(p_DataToFind, "", false, false);
          }
    }
      function getFullSearchResult(p_DataToFind) {
            var pageUrl = '<%=ResolveUrl("~/WebServices/Tools.asmx/")%>';
            $.ajax({
                type: "POST",
                url: pageUrl + "FullSearch",
                data: "{ 'p_DataToFind': '" + p_DataToFind + "' }",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: (function (response) {
                    alert(response.d);
                }),
                error: function (msg) {
                    alert(msg.status + ' ' + msg.statusText);
                }
            });
        }


    Sunday, January 26, 2014 11:06 PM
  • User-330204900 posted

    You should start a new thread really :) but in answer there is no DD way to do what you are doing at the moment as everything is happening on the client side.

    Monday, January 27, 2014 4:19 AM
  • User-647007878 posted

    OK. Now, solution for me is:

    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public List<usp_FullSearch_Result> FullSearch(string p_DataToFind)
    {
        using (AAEntities myEntity = new AAEntities())
        {
            List<usp_FullSearch_Result> fullListResult = new List<usp_FullSearch_Result>();
    
            var fullResult = myEntity.usp_FullSearch(p_DataToFind, "Text", false, false);
            foreach (usp_FullSearch_Result oneFullResult in fullResult)
            {
                fullListResult.Add(onefullResult);
            }
    
            return fullListResult;
        }
    }

    and then i process result on the client side. Thank you!

    Because so many information in my Dynamic Data project, i decided to implement full search (not only within one table) like Google ;) search.

    Monday, January 27, 2014 4:38 AM
  • User-833090171 posted

    sjnaughton

    Still nothing I'm afraid with the fully scaffolded DD but there may be a way using Model Binding that was introduced for Web Froms in .Net 4.5 and enhanced in .Net 4.5.1

    Thank you for the recommendation.

    Binding to a model complex type on the control level indeed seems to work fine. I.e. the following works.

    <asp:DynamicControl runat="server" ID="MyID"  DataField="MyComplexTypeProperty"  Mode="Edit" />

    However, entity templates, like the following…

    <asp:DynamicEntity runat="server" Mode="Edit" />

    Seem to completely ignore the complex type fields with no errors or warnings. The System.Web.DynamicData.MetaTable.GetScaffoldColumns skips over the complex type columns; something sets Scaffold: false on the complex type columns, even when the model property is specifically decorated with ScaffoldColumn(true) attribute..

    How would you recommend fixing that?

    Monday, January 27, 2014 6:11 PM
  • User-833090171 posted

    Here is a quick and dirty workaround for the above.

    In the beginning of the OnLoad event handler (before the call to the GetScaffoldColumns) for the Dynamic Data Entity Template add the following:

                foreach (MetaColumn column in Table.Columns)
    
                    if (column.ColumnType == typeof(MyComplexType))
    
                        column.Scaffold = true;

     

    The side effect is that the ScaffoldColumn(false) attribute will be ignored for all instances of MyComplexType rendered by this template.

    Monday, January 27, 2014 7:03 PM
  • User-330204900 posted

    Pleas could you post your full Entity Template and also a screen shot of your Comples entity and I will work that in to my up and coming open source Dynamic Data Extensions.

    Tuesday, January 28, 2014 5:01 AM
  • User-833090171 posted

    The Entity Template is the standard template that comes in the Microsoft DynamicDataTeplatesCS NuGet package.

    Attached is the screenshot of six properties of the same complex type rendered. In this case the complex type consists of two DateTime properties, one for estimated DateTime and one for actual DateTime, they are being rendered side-by-side.

    Complex Types Screenshot

    Tuesday, January 28, 2014 4:40 PM
  • User-330204900 posted

    hi there I'll see what I can do to make this work out of the box (well my box that is see https://github.com/sjnaughton/bootstrap-friendly-dynamic-data)

    Wednesday, January 29, 2014 5:24 AM