Asked by:
Looking for full sample demo of Dynamic Data with Entity Framework

Question
-
User2102128812 posted
I've been surfing the web, and I have not yet found a full sample demo, ie, something with enough substance to demonstrate a real world scenario and not just little code snippets here and there.
I'm especially interested in a demo that shows use of the various customisation techniques in both the data layer (using the entities code-generated by the Entity Data Model of the Entity Framework) and also in the presentation layer (using various customised field templates etc).
I should also mention that although I have successfully wired up a database with Entity Data Model to Dynamic Data, I have not succeeded in getting customized page templates to work. I follow all the directions (eg, name the subdirectory under CustomPages with the same name as the data entity, etc) but it just does not work. No errors are ever returned. It's just that the CustomPages customised page templates never get recognized, and the standard page templates are used instead.
I have also noticed that I could never get the project template to work in the first place without changing all the CodeBehind's to CodeFile's....
Sunday, September 21, 2008 9:38 PM
All replies
-
User1641955678 posted
The Dynamic Data Futures app includes some examples of using a custom page. Not sure why it wouldn't work for you, unless you're not using the right directory name. Make sure you use the name of the Entity Set (e.g. Products), and not the Entity class (e.g. Product). It may just be a pluralization issue.
As for CodeBehind vs CodeFile, it depends on whether you're using a Web App Project or a Web Site.
David
Sunday, September 21, 2008 11:49 PM -
User2102128812 posted
I've been going around and around in circles on these problems, and I would appreciate some clear and explicit clarification from the Microsoft Dynamic Data Team.
I have been comparing the different project templates for Dynamic Data Entities Web Applications versus Web Sites for Visual Basic. And there are definitely inconsistencies with different code for example in the Global.asax files. Note for example the MISSING routes in the Global.asax for the DDE Web Sites template in Visual Basic.
When I started originally, I did so with a Web Application template that had "CodeBehind"s and I could not get it to work until I switched to "CodeFile"s. Finally, got that to work but not the customized page templates which do clash with the default templates even after clarifying the name pluralization...
So here are some explicit questions for the current platform of Windows Server 2008 Standard, Visual Studio 2008 Pro SP1, ASP.NET 3.5 SP1 all patched up-to-date:
1) Has the DDE Web Application Project Template in Visual Basic been tested on this platform? Is it supposed to have "CodeBehind"s or "CodeFile"s? Is the Entity Data Model, designer class and any associated partial classes supposed to go in any special directory such as App_Code? Are customised page templates supposed to go in a different namespace in order to avoid clashing with the default page templates of the same name?
2) Has the DDE Web Sites Template in Visual Basic been tested on this platform? Is it supposed to have "CodeBehind"s or "CodeFile"s? Is the Entity Data Model, designer class and any associated partial classes supposed to go in any special directory such as App_Code? Are customised page templates supposed to go in a different namespace in order to avoid clashing with the default page templates of the same name?
Or should I conclude that it all really only works in C# because that's apparently the only language that shows up in samples and blogs and/or used by the development team at Microsoft?
Monday, September 22, 2008 1:57 AM -
User-330204900 posted
Hi ctaswell, Most people on the forum seem to work in c# but there are a few who work in VB, as far as you questions are concerned:
1) Has the DDE Web Application Project Template in Visual Basic been tested on this platform? Is it supposed to have "CodeBehind"s or "CodeFile"s? Is the Entity Data Model, designer class and any associated partial classes supposed to go in any special directory such as App_Code? Are customised page templates supposed to go in a different namespace in order to avoid clashing with the default page templates of the same name?
2) Has the DDE Web Sites Template in Visual Basic been tested on this platform? Is it supposed to have "CodeBehind"s or "CodeFile"s? Is the Entity Data Model, designer class and any associated partial classes supposed to go in any special directory such as App_Code? Are customised page templates supposed to go in a different namespace in order to avoid clashing with the default page templates of the same name?
The "CodeBehind"s or "CodeFile" is a Web Application Project vs file based Website it particulartly affects user controls i.e. most of the foilders in the DynamicData folder structure. Again the App_Code folder is a file based Website requrement in that all classes that are not pages must live in here.
NOTE: the above issues only occur when copying file between project types.
The only namespace issues that I am aware of is in the Web Application Project where each page is a seperate class and MUST be named as sutch, i.e. if you copy the List.aspx page from the ~/DynamicData/PageTemplates folder to say the ~/DynamicData/CustomePages/Orders/ folder then the class name should be changed e.g.List to OrdersList, this is only an issue with Web Application Project.
But with the file based Website each page class must be unquie in its folder as folder names are built into the classes at complile time.
Hope this helps [:D]
Monday, September 22, 2008 3:28 AM -
User2102128812 posted
Thanks much for some of these clarifications. I do now have a basic Dynamic Data setup working even with access to a CustomPages subdirectory.
However, I still have lots of questions which maybe the Microsoft Team and Forum Experts take for granted. And so, I am still looking for a more meaningful and more helpful sample demo that actually shows how to use Dynamic Data with the Entity Framework and an Entity Data Model and EntityDataSource, etc, etc...
Please note that as far as I can tell (unless I missed it), the Dynamic Data Futures download from Microsoft does not have any Entity Data Model samples. So far, I've only found LINQ to SQL samples in that download. So I'd really appreciate it if either Microsoft Team or a Dynamic Data Forum Expert would point me to a meaningful sample demo with both Dynamic Data and the Entity Framework.
I'd like to see clear use of different examples of how to initialize Entity instances with default values such as NewGuid()'s in the data layer for EntityKey's that use Guid's. So far, my attempts have failed, and on Insert in Dynamic Data the default values do NOT show up in the presentation layer. So what is the correct way to do this? And which are the recommended events such as OnInit, OnInsert, or OnValidate that I should be using for Dynamic Data with Entity Framework? And how should I be accessing them? With which handlers? Or better yet, where is the timeline sequence of all events that can be called? And what are the recommendations for the different ways of doing it?
In my opinion, and I will argue this as strongly as I can, these new technologies should not be released from Microsoft as official releases (ie, no longer called previews, futures, betas, or release candidates) unless they are shipped with demonstration samples AS PART OF the official release. I should not have to search everywhere and all to no avail. In fact, I am going to argue that unless the technology is shipped with clear and compelling demonstration samples packaged together with the software (so I don't have to search for the demos and/or plead for one on a Forum like this one), then the technology is not yet ready for primetime! My point is that the proof is in the pudding. So where's the pudding?
Monday, September 22, 2008 3:09 PM -
User-1005219520 posted
Hi ctaswell,
Dynamic Data (DD) does not display GUIDs by default. In general, GUIDs are not useful for humans to enter by hand, edit, insert. If you build a DD web site using the AdventureWorksLT (AWLT) database with either Link to SQL (L2S) or ADO Entity Framework (EF) and view the address table, the rowguid column will not be displayed. To display it, use the ScaffoldColumn attribute (passing in true).
Using the Address table of AWLT again as a sample, I add the following Address entity constructor to my partial class to initialize a new GUID. I'm now able to insert a new address into the table.
public partial class Address { public Address() { rowguid = Guid.NewGuid(); } }
I don't consider this an ideal solution as a bogus GUID gets generated for each row fetched from the DB, but it does solve the problem. The EF folks seem to prefer you edit the wizard generated EDMX file and add the StoreGeneratedPattern="Computed" attribute to the rowguid property of Address entity in the SSDL.
<Property Name="rowguid" Type="uniqueidentifier" Nullable="false" StoreGeneratedPattern="Computed"/>
<Property Name="ModifiedDate" Type="datetime" Nullable="false" StoreGeneratedPattern="Computed"/>There are many samples using Entity Framework in
the Dynamic Data documentation on MSDN.
The first versions of our documents had only Link to SQL
All sample contain VB and C#.
as only Link to SQL was supported at the time of writing.
We are in the process of updating the documents.
All new document will show any differences between Link to SQL and Entity Framework.
Many of the newer samples use Entity Framework, and all the new content should
show differences between the two data models.
We would appreciate your feedback on our documentation.My blog Differences When Working with the ADO.NET Entity Framework to LINQ to SQL
might have some items to help get you started.
A new update to Dynamic Data on MSDN will show in a couple weeks.
We've added several new samples using EF and updated others.
Among many other addtions, the update shows how to use the OnSavingChanges
method in a partial class to validate all properties in an entity.
Let me know if this is something you need before the update appears.Below is the partial class I like to use with the Address table of AWLT. Note I did cheat a bit and apply the StoreGeneratedPattern="Computed" attribute to the ModifiedDate property of the Address entity.
using System; using System.ComponentModel.DataAnnotations; namespace AdventureWorksLT2008Model { [MetadataType(typeof(Address_MD))] public partial class Address { public Address() { rowguid = Guid.NewGuid(); } } partial class Address_MD { [ScaffoldColumn(true)] public object rowguid { get; set; } [ScaffoldColumn(false)] public object ModifiedDate { get; set; } [ScaffoldColumn(false)] public object AddressID { get; set; } } }
Monday, September 22, 2008 9:27 PM -
User2102128812 posted
While your remarks are appreciated, I must say that we have very different opinions and expectations about demo samples, at least as reflected by your statement that "There are many samples using Entity Framework in the Dynamic Data documentation on MSDN."
So let me be clear that I did read every single page of the documentation in that section of the MSDN library, and it is not sufficient for an adequate understanding of how the DD development team intends this new technology to be used - at least not for me, and I'm not the least bit embarassed to say so. Nor does your brief blog post suffice.
As far as I'm concerned, a sufficiently comprehensive sample demo should be enough to show both the big picture and the little details. Note that an assorted collection of bits and pieces that seem more like unit-tests than anything else just does NOT do it.
There should be a sufficiently complete and sufficiently real-world scenario sample that clearly shows intended use of how to use the various initialization, validation, and processing event handlers with the various objects (whether EntityObject, EntityDataSource, and all the DynamicData objects) in the multiple layers of the overall application - of course subject to the requirement that we are using the fundamental approach of combining the Entity Framework with Dynamic Data. And I will repeat my statement that "official RTM" of new technology should not be released without working samples that exercise and demonstrate the technology. That used to be the standard for many software companies back in the 1980's and 1990's but apparently has been lost or forgotten or else the bar has just been lowered... Again I'm not convinced that this stuff works the way it's supposed to work unless it is actually shipped with a comprehensive working sample that demo's the technology, and I should NOT have to go search to download the demo from somewhere else... So until then it should just be called another release candidate or advanced beta or something or "futures" or ... else Microsoft continues the practice of confirming the oft-quoted advice that one shouldn't even think of using new Microsoft technology until after the third "official" release...
So if you really do have a meaningful real-world scenario demo sample of Dynamic Data with Entity Framework using Visual Basic, then I will be more than happy to study it and post my critique right here with a list of questions and comments regarding what is missing and what needs to be added to make it a meaningful and useful sample demonstration that enables a developer like me to learn and understand how to use the new technology without spending inordinate amounts of time trying to track things down or waste a lot of time experimenting instead of following useful examples...
And please note that my remarks here do remain on the thread topic of "Looking for full sample demo of Dynamic Data with Entity Framework" in Visual Basic please
Tuesday, September 23, 2008 12:28 AM -
User-1005219520 posted
Let me know if you find any samples in the Dynamic Data documentation on MSDN that are not trivial to convert from L2S to EF. I've found a few and updated the documents as mentioned previously - the updated docs will post in a couple weeks.
Tuesday, September 23, 2008 11:46 AM -
User2102128812 posted
In your previous post from yesterday, you asked me to let you know if I wanted access to the samples/docs before the update appears.
In my reply, I thought I stated clearly that I did, that I would be happy to look at it and comment on it.
Have you withdrawn your offer?
Tuesday, September 23, 2008 12:01 PM -
User-1005219520 posted
Among many other addtions, the update shows how to use the OnSavingChanges method in a partial class to validate all properties in an entity. Let me know if this is something you need before the update appears.Send me your alias from http://forums.asp.net/members/ricka6.aspx and I'll send you the EF additions I made to use the OnSavingChanges
method. I'll find out when the documents should post and report back.Tuesday, September 23, 2008 1:54 PM -
User2102128812 posted
Look, there's a real disconnect here in the communication. I'm not interested in another little code snippet.
I have found plenty of commentary and criticisms elsewhere about Entity Framework and Entity Data Model that suggest it's not ready for prime-time. The only way to disprove these criticisms and/or prove just what does and does not work is to package and ship with the technology release and a full and complete real-world scenario demonstration that proves what does and does not work in a real-world setting application. Note that a demonstration is NOT documentation. I can infer what documentation I need from the code in the demonstration itself. Just to re-emphasize my point, what is needed is a real demonstration because documentation without demonstration is not in any way sufficient.
And since Microsoft has decided to abandon the standards of demonstration (and documentation) maintained by other companies (consider for example the standards maintained by Telerik), then I have decided to respect the advice recommended by those who know better: Don't waste time with new Microsoft technologies until AFTER at least the third official release.
And I will leave to those adventurous Microsoft MVP's who like to write magazine articles, books, teach at conferences do all the heavy time-wasting lifting to work out and report all the bugs and deficiencies in the early "official" releases.
Sorry to be so candid. But it's time to call a spade a spade. And Microsoft needs to set and maintain at least some minimum level of demonstration and documentation when it releases new technologies. Otherwise it will continue to frustrate and alienate experienced software developers such as myself. And yes I have been a software developer for more than three decades on many different platforms with many different technologies... and I can tell the difference between those technologies that are released with adequate demonstration and documentation and those that are not. And remember demonstration is different from documentation.
Monday, September 29, 2008 1:21 PM -
User-1246852455 posted
I too would like to see a demo app using Entities. I can find the Linq to SQL til I'm blue in the face, but I can't find one using Entities.
Here is a post by David Hayden on setting up an Entity application, but nothing on customizing it:Looking around I found this, which I didn't find useful as far as training me how to do custom properties or anything, but am sharing because there might be something useful:
http://blogs.msdn.com/adonet/search.aspx?q=dynamic+data+entities&p=1
Anyway, yes, I would like to see an Entities sample that shows how to customize classes as well.
Thursday, November 6, 2008 1:36 PM -
User-1005219520 posted
Hi Nannette,
All the MSDN Dynamic Data doc's have samples the spell out the differences between EF and L2S (if you find any missing let me know). They also provide equal VB samples. I think the best approach is to find a sample you like (in L2S) and then try it with EF. IF you have a problem, look to the MSDN Dynamic Data doc's which spell out the EF and L2S differences.
ExistingWebsite_Entities.zip on codeplex ( http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=14473 ) should get you started. I'm working on a full sample with lots of customizations using the AdventureWorksDB. I'm developing it in c# and VB - but it won't be ready for another month or more. I'm slow in VB.
Thursday, November 6, 2008 2:28 PM -
User-1246852455 posted
Thanks so much! I don't know why googling, I could not find this stuff.
Meanwhile, the ExistingWebSite app works out of the box, but the Scaffold_Entities is another story.
Now I'll be the first to admit I'm ignorant on a lot of subjects, so maybe this is a no-brainer for you, but for me, I don't have a clue what it means.
Compiler Error Message: CS0234: The type or namespace name 'DataAnnotations' does not exist in the namespace 'System.ComponentModel' (are you missing an assembly reference?)
Line 5: using System.ComponentModel.DataAnnotations;
Source File: c:\Webs\dynamicdata\Scaffold_Entities\App_Code\Metadata.cs Line: 5
And there are more:
Error 2 The type or namespace name 'Objects' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) C:\Webs\dynamicdata\Scaffold_Entities\App_Code\Model.Designer.cs 11 32 C:\...\Scaffold_Entities\
Error 3 The type or namespace name 'Objects' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) C:\Webs\dynamicdata\Scaffold_Entities\App_Code\Model.Designer.cs 11 32 C:\...\Scaffold_Entities\
Error 4 The type or namespace name 'Objects' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) C:\Webs\dynamicdata\Scaffold_Entities\App_Code\Model.Designer.cs 12 32 C:\...\Scaffold_Entities\
Thursday, November 6, 2008 3:46 PM -
User-1005219520 posted
They key is the error message "are you missing an assembly reference?)" - you are indeed missing a ref.
I just downloaded it and I don't get any errors. Did you open it as a web site? Do you have VS/SP1 installed? For System.ComponentModel.DataAnnotations you need a reference to System.ComponentModel.DataAnnotations. Try adding that. Can you remove a few of the error lines so this thread isn't too long?
Thursday, November 6, 2008 4:10 PM -
User-1246852455 posted
I opened it as a website. there wasn't a project file in the zip. Should this be a project?
I have vs 2008 sp1 tools and vs 2008 sp1 win32 tools installed. Is that what you mean?
I added a reference to system.componentmodel.dataannotations.
Does this run immediately for others, or do they have to add references first? I've not worked with tutorials that require adding references before.
Now it says:
"The type or namespace name 'Objects' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)"
I keep adding system.data reference and it still gives the same error.
Friday, November 7, 2008 11:01 AM -
User-330204900 posted
If there is no Project file then you will find that it is a file based website as you would get by clicking file new website (if you have set VS2008 up for web development). So you would use File Open Website in stead of File Open Project.
Hope this helps [:D]
Friday, November 7, 2008 11:46 AM -
User-1005219520 posted
>>Should this be a project?
No, it should be opened as a web site.
>>Does this run immediately for others, or do they have to add references first?
I just tested it on two machines (Vista SP1 & Win08) - both with VS08/SP1 - no problems. It has lots of downloads and this is the first reported problem. Can you try downloading it again? This is what the property pages dialog shows:
Reference Name Type Version
Microsoft.Web.DynamicData.EFProvider BIN 1.0.0.0
System.ComponentModel.DataAnnotations GAC 3.5.0.0
System.Core GAC 3.5.0.0
System.Data.DataSetExtensions GAC 3.5.0.0
System.Data.Entity GAC 3.5.0.0
System.Data.Entity.Design GAC 3.5.0.0
System.Data.Linq GAC 3.5.0.0
System.Security GAC 2.0.0.0
System.Web.Abstractions GAC 3.5.0.0
System.Web.DynamicData GAC 3.5.0.0
System.Web.Extensions GAC 3.5.0.0
System.Web.Routing GAC 3.5.0.0
System.Xml.Linq GAC 3.5.0.0
Friday, November 7, 2008 4:51 PM