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.
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.
Still looking into it but if this rattles any cages let me know.
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.
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 :)
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.
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.
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
Dynamic Data 4
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
Re: Displaying Complex Types in a Dynamic Data Web Site
Jan 26, 2014 11:06 PM|konstantin.konstantinov|LINK
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);
}
}
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.
Dynamic Data 4
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
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.
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..
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.
Dynamic Data 4
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
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.
Member
234 Points
94 Posts
Displaying Complex Types in a Dynamic Data Web Site
Mar 10, 2010 09:43 AM|MrDaveM|LINK
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?
All-Star
17916 Points
5681 Posts
MVP
Re: Displaying Complex Types in a Dynamic Data Web Site
Mar 10, 2010 01:58 PM|sjnaughton|LINK
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.
Entity Framework Dynamic Data 4 Complex Types
Always seeking an elegant solution.
Contributor
3384 Points
1363 Posts
Re: Displaying Complex Types in a Dynamic Data Web Site
Mar 10, 2010 02:48 PM|davidebb|LINK
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
Member
234 Points
94 Posts
Re: Displaying Complex Types in a Dynamic Data Web Site
Mar 10, 2010 04:01 PM|MrDaveM|LINK
Thanks guys, I will have a look at this tonight and get a post on my findings.
Member
234 Points
94 Posts
Re: Displaying Complex Types in a Dynamic Data Web Site
Mar 10, 2010 05:55 PM|MrDaveM|LINK
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.
Still looking into it but if this rattles any cages let me know.
Contributor
3384 Points
1363 Posts
Re: Displaying Complex Types in a Dynamic Data Web Site
Mar 10, 2010 06:14 PM|davidebb|LINK
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
Member
234 Points
94 Posts
Re: Displaying Complex Types in a Dynamic Data Web Site
Mar 10, 2010 06:36 PM|MrDaveM|LINK
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!
Anyway, its late now so I will shelve this till tomorrow evening.
Contributor
3384 Points
1363 Posts
Re: Displaying Complex Types in a Dynamic Data Web Site
Mar 10, 2010 06:48 PM|davidebb|LINK
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 :)
Member
234 Points
94 Posts
Re: Displaying Complex Types in a Dynamic Data Web Site
Mar 10, 2010 06:55 PM|MrDaveM|LINK
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
Member
50 Points
28 Posts
Re: Displaying Complex Types in a Dynamic Data Web Site
Mar 11, 2010 07:15 AM|yacine|LINK
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:
Member
234 Points
94 Posts
Re: Displaying Complex Types in a Dynamic Data Web Site
Mar 12, 2010 06:13 PM|MrDaveM|LINK
Thanks for the info Yacine.
None
0 Points
13 Posts
Re: Displaying Complex Types in a Dynamic Data Web Site
Jan 19, 2011 05:17 AM|kkara|LINK
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
All-Star
17916 Points
5681 Posts
MVP
Re: Displaying Complex Types in a Dynamic Data Web Site
Jan 19, 2011 05:35 AM|sjnaughton|LINK
Hi Kkara, I don't believe there is at the moment.
Dynamic Data 4
Always seeking an elegant solution.
Member
42 Points
28 Posts
Re: Displaying Complex Types in a Dynamic Data Web Site
Jan 23, 2014 09:09 PM|TObject|LINK
Hello,
Any news on this?
Thanks.
Dynamic Data 4
All-Star
17916 Points
5681 Posts
MVP
Re: Displaying Complex Types in a Dynamic Data Web Site
Jan 24, 2014 05:42 AM|sjnaughton|LINK
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
Dynamic Data 4
Always seeking an elegant solution.
Member
1 Points
24 Posts
Re: Displaying Complex Types in a Dynamic Data Web Site
Jan 26, 2014 11:06 PM|konstantin.konstantinov|LINK
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):
Dynamic Data 4
All-Star
17916 Points
5681 Posts
MVP
Re: Displaying Complex Types in a Dynamic Data Web Site
Jan 27, 2014 04:19 AM|sjnaughton|LINK
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.
Dynamic Data 4
Always seeking an elegant solution.
Member
1 Points
24 Posts
Re: Displaying Complex Types in a Dynamic Data Web Site
Jan 27, 2014 04:38 AM|konstantin.konstantinov|LINK
OK. Now, solution for me is:
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.
Dynamic Data 4
Member
42 Points
28 Posts
Re: Displaying Complex Types in a Dynamic Data Web Site
Jan 27, 2014 06:11 PM|TObject|LINK
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?
Dynamic Data 4
Member
42 Points
28 Posts
Re: Displaying Complex Types in a Dynamic Data Web Site
Jan 27, 2014 07:03 PM|TObject|LINK
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:
The side effect is that the ScaffoldColumn(false) attribute will be ignored for all instances of MyComplexType rendered by this template.
Dynamic Data 4
All-Star
17916 Points
5681 Posts
MVP
Re: Displaying Complex Types in a Dynamic Data Web Site
Jan 28, 2014 05:01 AM|sjnaughton|LINK
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.
Dynamic Data 4
Always seeking an elegant solution.
Member
42 Points
28 Posts
Re: Displaying Complex Types in a Dynamic Data Web Site
Jan 28, 2014 04:40 PM|TObject|LINK
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.
Dynamic Data 4
All-Star
17916 Points
5681 Posts
MVP
Re: Displaying Complex Types in a Dynamic Data Web Site
Jan 29, 2014 05:24 AM|sjnaughton|LINK
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)
Dynamic Data 4
Always seeking an elegant solution.