Luc Vo Van, one of my colleges has recently created the Windows Live Writer Silverlight App Plugin. Here is the link, really easy to use :
http://blogs.msdn.com/luc/archive/2009/11/19/windows-live-writer-silverlight-app-plugin.aspx
Many Thanks Luc :-)
Introduction
In this post, I’ll give you some tips interesting that helped me in my several projects.
For more information on Data Services, I suggest you to read my previous posts:
TIPS 1 : ADO.NET Data Services CTP 1.5 CTP 2
Accessible here, this new release targeting .net 3.5 & Silverlight 3 provides some great new features (some more details about this release):
- Projections;
- Better data binding;
- Row count;
- Server Page Driven;
- …
-> One of the major feature of this version is to allow cross domain access to your Data Services from your Silverlight application.
Here you can access to a description of this feature written in the ADO.NET Data Services Team Blog.
TIPS 2 : Returning hierarchical data
A great advantage of returning hierarchical in advance to reduce the number of server calls especially when you know that the hierarchical data is needed.
In the following example, the request will return a specific product:
Code Snippet
- public DataServiceQuery<Product> ReturnHierarchicalData(int productId)
- { // Create a hierachical data query
- DataServiceQuery<Product> request = (from product in _adventureWorksProxy.Products
- .Expand("ProductSubcategory")
- .Expand("ProductSubcategory/ProductCategory")
- where product.ProductID == productId
- select product) as DataServiceQuery<Product>;
-
- return request;
- }
This request will returns the specific ProductSubCategory entity of the product and the ProductCategory of this ProductSubcategory.
TIPS 3 : Deferred loading
In opposition to hierarchical data return in a single call, when the size of data to return is too heavy, you should use deferred loading.
In this example, I will return the ProductSubcategory of the product only when needed.
Code Snippet
- void ReturnDeferredData(Product product)
- {
- // Deferred load
- _adventureWorksProxy.BeginLoadProperty(product, "ProductSubcategory", ReturnDeferredDataCallBack, product);
- }
- void ReturnDeferredDataCallBack(IAsyncResult ar)
- {
- _adventureWorksProxy.EndLoadProperty(ar);
- Product product = ar.AsyncState as Product;
- }
BeginLoadProperty requires four parameters, the entity used for deferred loading, the name of the property used in the deferred mechanism, the callback ant the context.
The callback method will end the asynchronous system.
TIPS 4 : Batching requests
One other great feature of Data Services is batching. it allows you to request in a same time several requests to the server and to return the result only in one time.
This example shows how to execute two requests on the server with only one server access. You can check using fiddler to confirm :-)
Code Snippet
- // Creation of two requests
- var request1 = new DataServiceRequest<Product>(new Uri("Products",UriKind.Relative));
- var request2 = new DataServiceRequest<ProductSubcategory>(new Uri("ProductSubcategory", UriKind.Relative));
-
- // Execution of those two requests on the server
- DataServiceResponse responses = adventureWorksProxy.ExecuteBatch(request1, request2);
- foreach (QueryOperationResponse response in responses)
- {
- if(response.Query.ElementType == typeof(Product))
- {
- // ...
- }
- else if (response.Query.ElementType == typeof(Product))
- {
- // ...
- }
- }
Here is an interesting post from ADO.NET Data Services Team Blog.
I’m a real fan of MSBuild Scripts, I always use a lot of MSBuild Tools in my projects (for example scripts that automatically get latest version of the code, compile, check-in, …).
The easier way I found to execute those scripts is to run them automatically while I am clicking on a button into my Visual Studio.
STEP 1: Creation of an external tool
In Visual Studio 2010, Click on “Tools” menu, “External Tools …”.
A pop-up appears, click Add button and enter the desired information.
“Title” textbox is used as the name of the button that will be created.
If you use MSBuild on a X64 operating System, you have to select x86 MSBuild version:
C:\Windows\Microsoft.NET\Framework\v4.0.21006\MSBuild.exe
Click on “Use Output window” checkbox to redirect the result of your MSBuild script into Visual Studio Output window.
Step2 : Creation of your Toolbar and affectation of the external tool
On the menu bar, right click and select “Customize …”.
A pop-up appear, create your desired toolbar. Name it MyToolbar and click OK.
Click on the “Commands” tab and click on ToolBar radio button to select the newly created external tool.
Select MyToolBar and click on “Add Command …” button.
On the left lit item, select “Tools” and than select the “External Command x” item where X is the index of your tool that appears in the “Tool” menu (starting index => 1). In my example “External Command 6”.
Click “Ok” and than “Close”.
And here is the result :-)

Introduction
In this post I will talk about how you can consume your ADO.NET Data Services. My examples will be based on WPF.
For more information on Data Services, I suggest you to read my previous posts:
Consuming in WPF
Creates a WPF application named MyWPFApplication.

Add a reference to your Data Service, right click on MyWPFApplication project, and select Add service reference. A windows appears, define the address, rename the namespace with MyDataServiceProxy and click on OK button.
In MainWindow.xaml.cs, write the following code:
Code Snippet
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
- }
-
- void MainWindow_Loaded(object sender, RoutedEventArgs e)
- {
-
- // Define the URI of the Data Service Query
- Uri uri = new Uri(@"http://localhost:34570/AdventureWorksService.svc/");
- // Create an instance of the Data Service context
- MyDataServiceProxy.AdventureWorksModel.AdventureWorksEntities adventureWorksProxy = new MyDataServiceProxy.AdventureWorksModel.AdventureWorksEntities(uri);
- // Create your query
- var query = (from product in adventureWorksProxy.Products
- select product).Take(10);
- // Set the qury result into the DataContext
- this.DataContext = query;
- }
- }
In the loaded event, instantiate your DataService. Create a simple request using Linq syntax and put this query into the DataContext.
In MainWindow.xaml, bind the data grid with the DataContext :
Code Snippet
- <Window x:Class="MyWpfApplication.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="MainWindow" Height="350" Width="525">
- <Grid>
- <DataGrid AutoGenerateColumns="true" Height="287" HorizontalAlignment="Left" Margin="12,12,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="479"
- ItemsSource="{Binding}">
- </DataGrid>
- </Grid>
- </Window>
Press F5 and here is the result:

This post shows how easy it is to consume Data Services with WPF. Just few code lines are needed ;-)
Introduction
In this post I will talk about Operations & Interceptors functionalities included into ADO.NET Data Services.
For more information on Data Services, I suggest you to read my previous posts:
Operations
If you need to aggregate an operation, instead of creating the rule on the client side (on each sort of client application), you can centralize it easily on the server side using Operators.
In the following example, GetProductsByColor returns all products of a specific color.
Code Snippet
- [WebGet]
- public IQueryable<Product> GetProductsByColor(string color)
- {
- return from product in this.CurrentDataSource.Products
- where string.Compare(color, product.Color) == 0
- select product;
- }
The WebGetAttibute is used to request your service via REST.
Inside the method, you just have to write your Linq query on the CurrentDataSource to get the desired result.
You also need to define the Service Operation Access Control. You have to grant read access to the operation. Here is the code to add in the InitializeService method:
Code Snippet
-
- config.SetServiceOperationAccessRule("GetProductsByColor", ServiceOperationRights.AllRead);
InitializeService is the method where you already have granted access to the Data Service.
And finally, you can execute the code with this URL:
http://localhost:34570/AdventureWorksService.svc/GetProductsByColor?color='Red'
Interceptors
Interceptors is the Data Services mechanism to customize logic on the server side. With this mechanism, you can intercept queries and add specific restriction rules.
Example 1 : Interceptor on a query request
In the following example, you will create :
- a filter to check if the person requesting the DataService service on the Products entity is member of the Admin role (defined for example with ASP.NET role provider), else an exception is thrown;
- only Products where SellEndDate property is not null;
Open you DataService class. Don't forget to add at the top of you file:
Code Snippet
-
- using System.Linq.Expressions;
Create the filter method on the product entity. You need to create a function prefixed with QueryInterceptor attribute. This attribute expects the name of the entity on which the interceptor will be applied (as defined in the Data Service Workspace http://localhost:34570/AdventureWorksService.svc/). The method has to follow a specific signature.
Code Snippet
- [QueryInterceptor("Products")]
- public Expression<Func<Product, bool>> FilterProducts()
- {
- if (HttpContext.Current.User.IsInRole("Admin"))
- return (p => p.SellEndDate !=null);
- else
- throw new UnauthorizedAccessException("You don't have access to this information");
- }
Example 2 : Interceptor on a change query (Add, Change, Delete, … operation)
In this example, I’m just checking that only Admins have granted privileges for adding,updating or deleting Product entity set. The signature of the method is a little bit different from previous example.
Code Snippet
- [ChangeInterceptor("Products")]
- public void onChangeProducts(Product product, UpdateOperations operations)
- {
- if (!HttpContext.Current.User.IsInRole("Admin"))
- throw new UnauthorizedAccessException("You don't have access to this information");
- }
For more information, I suggest you to read MSDN documentation.
Introduction
In my previous post, I explained how to create a ADO.NET Data Service with Visual Studio 2010. In this post, I will explain how to request this Data Service using Internet Explorer (but this will also work in any other browser). The database used in previous post is AdventureWorks.
Listing and filtering entities
By default when accessing the service, the list of all entities is returned.
http://localhost:34570/AdventureWorksService.svc
http://localhost:34570/AdventureWorksService.svc/Products
This request lists all products existing in the database.
Let’s go further, you would like to return articles 6 to 7 order by ProductNumber:
http://localhost:34570/AdventureWorksService.svc/Products?$orderby=ProductNumber&$skip=5&$top=2
| REST Syntax | Description |
| $orderby=ProductNumber | order Products by ProductNumber |
| &$skip=5 | and skips the first 5 rows |
| &$top=2 | and returns the two first rows |
You could also order the results by ProductNumber descending:
http://localhost:34570/AdventureWorksService.svc/Products?$orderby=ProductNumber%20desc&$skip=5&$top=2
| REST Syntax | Description |
| $orderby=ProductNumber desc | order Products by ProductNumber descending |
| &$skip=5 | and skips the first 5 rows |
| &$top=2 | and returns the two first rows |
Here is the syntax to filter a product in particular:
http://localhost:34570/AdventureWorksService.svc/Products?$filter=ProductID%20eq%201
| REST Syntax | Description |
| $filter=ProductID eq 1 | where ProductID is equal to 1 |
http://localhost:34570/AdventureWorksService.svc/Products?$filter=ProductID%20ge%20900%20and%20ProductID%20lt%20950
| REST Syntax | Description |
| $filter=ProductID ge 900 | where ProductID is greater or equal to 900 |
| and ProductID lt 950 | and ProductID less than 950 |
Other expression syntaxes are available here.
Expanding SubEntities
One of the great feature of Data Services is the ability to also return referenced entites.
For example, if you want to request a specific Product, and also return the information defined in its ProductSubCategory property, the request is as follows:
http://localhost:34570/AdventureWorksService.svc/Products?$filter=ProductID%20eq%20771&$expand=ProductSubcategory
| REST Syntax | Description |
| $filter=ProductID eq 771 | where ProductID equals to 771 |
| &$expand=ProductSubcategory | and expands ProductSubcategory for this specific Product. ProductSubcategory is the name of the navigation property for ProductSubcategory in the Product entity defined in your emdx file |
And if you also need to retrieve the Catagory entity, which is two levels above :
http://localhost:34570/AdventureWorksService.svc/Products?$filter=ProductID%20eq%20771&$expand=ProductSubcategory,ProductSubcategory/ProductCategory
| REST Syntax | Description |
| $filter=ProductID eq 771 | where ProductID equals to 771 |
&$expand=ProductSubcategory, ProductSubcategory/ProductCategory | expands ProductSubcategory for this specific Product and ProductSubcategory/ProductCategory |
New features of Visual Studio 2010 beta 2
When your Data Service project is running with debugger inside VS2010, all the requests executed are listed into Visual Studio. Really great feature :-)

Introduction:
This post is the first of a series of articles based on Visual Studio 2010. In this one I will introduce you to publishing your data through ADO.NET Data Services. Here are the main interest for me into using Data Services:
- Exposing your data as a Data Service allows clients to consume it easily from using the technology you want (WPF, Silverlight, ASP.NET, J2EE, …);
- Addressing Scheme for Data with URIs;
- Data Transport Format ubiquitous (AtomPub or JSON);
- Data Storage independence;
- Usage of REST semantic;
Pre-requisites:
Visual Studio 2010 beta2 + SQL Server 2005 Express or 2008 Express http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx
AdventureWorks database http://www.codeplex.com/MSFTDBProdSamples/Release/ProjectReleases.aspx?ReleaseId=18407
Step 1 : Create your web application project
After installing all software pre-requisites, let’s begin.
Open Visual Studio 2010 beta 2 and create an empty ASP.NET Web application named MyDataServicesApplication, for example. This web project will contains the edmx (i.e. the Entity Data Model) file and the ADO.NET Data Services class.
Step 2 : Create an Entity Model of the AdventureWorks database
First of all, a edmx file has to be created.
Create a new Item, select ADO.NET Entity Data Model item template, name it AdventureWorksModel
Press the Add button and follow the configuration wizard step by step
Select Generate from database to generate the edmx file from the existing database structure.
Select the AdventureWorks database
Specify the name of the connection string used, the specified name is stored in the web.config file into the connectionString tags.
Click the checkbox next to the Tables element, in order to include all existing tables into your data model.
Check the Pluralize or singularize generated object names check box and specify AdventureWorksModel as the namespace. This will pluralize all collection property names, this is a new feature of Visual Studio 2010.
Step 3 : Create the ADO.NET Data Service
Create a new item, Select the ADO.NET Data Service template and name it AdventuWorksService.svc
Open AdventureWorksService.svc.cs and update the content to be like this:
Code Snippet
-
- namespace MyDataServicesApplication
- {
- public class AdventureWorksService : DataService<AdventureWorksEntities>
- {
- // This method is called only once to initialize service-wide policies.
- public static void InitializeService(DataServiceConfiguration config)
- {
- // Grant full access to all exsisting entities
- config.SetEntitySetAccessRule("*", EntitySetRights.All);
- // Grant full access for all operations
- config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
- config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
- }
- }
- }
Step 4 : Test
Press F5 to check the result, it should list all the available entities :

You can now request your database through REST, for example select all the products using this query (which is now just an URI!): http://localhost:34570/AdventureWorksService.svc/Products
The result is represented by default using the ATOM Publishing Protocol. Internet Explorer automatically applies a style on ATOM format to make it more readable. Here this is not the case :-). I suggest that you right click on the content of the page and select View Source, the result will be more user friendly.
Here is a link of the rest Services sementics, a usefull link : http://msdn.microsoft.com/en-us/library/cc668767.aspx
Conclusion
Here is a step by step guide for creating an ADO.NET Data Services with Visual Studio 2010 beta2.
CCF 2009 SP1 RTM has been released. This new version contains some new great features like :
- 64 bit client support;
- Dynamic positionning in IAD;
- Citric enhancement ;
- Usage for a same application of several DDAs;
- New platforms support;
- ...
You can found more details on those two new links:
Hands-On Labs for Enterprise Library 4.1 and Hands-On Labs for Unity Application Block 1.2 have been released few days ago; here is a the good opportunity to summarize some interesting links.
Enterprise Library:
Unity Application Block:
Pattern & practice:
Blogs:
· Gregori Melnik: http://blogs.msdn.com/agile
· J.D. Meier: http://blogs.msdn.com/jmeier
Here are the pre-requisits to use Sandcastle documentation:
Sandcastle is the tool for creating a code documentation, you can use the given examples to generate your documentation, everything works fine but all the documentation is in english.
How could I update that to have everything in french for example?
The solution is based on updating the xml files of the content folder of the choosen style.
Here are examples of steps for having your documentation in french:
- Duplicate all files xml files from <SandcastleInstallationDirectory>\Presentation\<Style>\Content\
- Duplicate shared_content.xml as shared_content_FR.xml (main file to translate, mostly everything is here)
- Duplicate reference_content.xml as reference_content_FR.xml
- Duplicate syntax_content.xml as syntax_content_FR.xml
- Translate all the xml content of the new created files;
- Update Sandcastle.config to point to those new files. Update this code:
<!--
Old code -->
<
component type="Microsoft.Ddue.Tools.SharedContentComponent" assembly="%DXROOT%\ProductionTools\BuildComponents.dll">
<
content file="%DXROOT%\Presentation\Prototype\content\shared_content.xml" />
<
content file="%DXROOT%\Presentation\Prototype\content\reference_content.xml" />
<
content file="%DXROOT%\Presentation\Shared\content\syntax_content.xml" />
</
component>
with this code:
<!-- Updated code -->
<component type="Microsoft.Ddue.Tools.SharedContentComponent" assembly="%DXROOT%\ProductionTools\BuildComponents.dll">
<content file="%DXROOT%\Presentation\Prototype\content\shared_content_FR.xml" />
<content file="%DXROOT%\Presentation\Prototype\content\reference_content_FR.xml" />
<content file="%DXROOT%\Presentation\Shared\content\syntax_content_FR.xml" />
</component>
Now you just have to try.
Benoît
Hi there,
Here is a little introduction about myself.
I'm Benoît Sarie, I'm a MCS Consultant for Microsoft France, I'm more dedicated on .net development and on Customer Care Framework (CCF) development.
If you don't already know what is CCF, I suggest you to read http://msdn.microsoft.com/en-us/isg/bb421305.aspx.
In this blog I'll try to give you tips and tricks on Visual Studio, WPF, P&P and on CCF.
See you soon on this blog :-)
Benoît