Last week I had an open house in Sela about the new features and improvements of WCF 4.
The video recordings of the lecture have been uploaded to Sela’s webcast site. You can register to the website, and after receiving your username and password, you can watch the videos from the following link.
If you only want to download the presentation and the demo’s source code, you can download it from here.
There is a known problem with Visual Studio 2010: when you open a context menu in the Solution Explorer it doesn’t always get expanded to fill to available height of the screen and you get a vertical scrollbar. On top of that, sometimes the mouse scroll doesn’t work also, and you have to move the cursor to the up/down arrows to scroll it yourself, which only adds to the frustration.
Usually I work with high resolutions (1920x1080) and the context-menu is shown without a scroll so I’m not that bothered with this problem, but when I give presentations and I have to lower my computer’s resolution this problem really bugs me.
Fortunately, the people at Microsoft Connect understood that this is annoying and passed the problem to the Visual Studio group who came up with a hotfix to solve this problem. After installing the hotfix, the context menu is expanded to the required height:
BTW, if you take a closer look at the clock in both picture – that is about the amount of time (10 minutes!!) it took me to install this hotfix on my computer.
The instructions on this blog states you should install both fixes (VS + WPF), but I currently installed only the Visual Studio hotfix and it works just fine without the other hotfixes (I think the other hotfix is for multiple monitors).
A few months ago, I read this great post about the Portable Extensible Metadata (PEM) of Entity Framework 4. The PEM relies on the extensibility of the entity framework EDM, which enables you to add your own XML content into the EDM. Once placed in the EDM, you can write code that investigates the MetadataWorkspace and do operations according to what you’ve written in the EDM.
One usage for example which is demonstrated in the PEM extension is adding validations to entities and properties, and placing this validation information inside the EDM for later use. To let the developer define the validation rules, the PEM demonstrates another technique – extending the entity framework designer. The entity framework designer is extensible in a way that you can add new properties in the properties window to configure entity types, properties, associations and more; you can even decide if the properties will be applied for the CSDL or the SSDL part of the EDMX. If you want to write your own extensions for the designer, take a look at the designer starter kit.
One thing that people noted about the PEM extension which also bothered me – the extension includes a new T4 template that creates C# validation code according to the validation rules it finds in the EDMX, but this code is simply “hard-coded” IF statements; it would be a great if the T4 could instead use the validation rules to apply data annotations to the generated entity classes, just like you can do with EF Code-Only.
So … I sat down and wrote a template for that purpose. I admit, I didn’t invest too much time in this, and didn’t cover all the validation types, but if you have use for this template, I’m sure you can add the missing pieces (if you do, I’d be happy if you can send me your updated template).
The template itself is based on the Self-Tracking template to which I’ve added some code to generate data annotation attributes for every primitive property.
Once your entities have data annotations, you can use them for example in ASP.NET MVC or Silverlight, and gain the automatic validation mechanism. You can also write another T4 to create validation methods that manually calls the System.ComponentModel.DataAnnotations.Validator class so you can validate you entities on the server side, for example before saving them to the DB (I might publish another post in the future with a sample template that does this).
To use the template, download the SelfTrackingWithDataAnnotationsCSharp.zip file and place it in the item templates folder under your documents folder (I recommend you reopen VS after you copy the file):
%userprofile%\Documents\Visual Studio 2010\Templates\ItemTemplates\Visual C#
Once you place the zip file in the folder (do not extract it, place it as it is), you’ll be able to add a new item called “ADO.NET Self-Tracking Entity Generator + Data Annotations” to your project (sorry for the length).
You can also add this file by right-clicking in an opened EDMX file and selecting “Add Code Generation Item…”.
Feel free to edit the template and improve it for your needs.