New Features in CTP2 ADO.NET Data Services v1.5 Explained
After yesterdays post about the availability of the CTP2 of ADO.NET Data Services v1.5 here are some more details regarding the Projections, Feed Customization and Data Binding.
As told before Projections, the possibility of getting only the columns chosen instead of retrieving all the columns. With this we have now a new set of expressions to provide this ability on the URI, and in order to achieve we have now two new keywords available, that are:
- $select, allow us to define which columns we want to be get
- Instead of using only the http://127.0.0.1/NorthwindService.svc/Customers that will return every column of the Entity Customer, we want to define that we only get the CustomerID and the ContactName, and in order to achieve this we use the new $select keyword like this http://127.0.0.1/NorthwindService.svc/Customers?$select=CustomerID,ContactName
- The way to define the several columns is to use commas to separate the column names.
- If we want to use this keyword and define all columns is the following http://127.0.0.1/NorthwindService.svc/Customers?$select=*
- $expand, defines that along with the results from the requested entity, we also want to get the results from a specific relationship
- But in order for this to work we need to add the following 2 properties to the service:
- First, make projections available using the URI.
1: config.DataServiceBehavior.AcceptProjectionRequests = true;
- Secondly, make the protocol version to V2
1: config.DataServiceBehavior.MaxProtocolVersion = System.Data.Services.Common.DataServiceProtocolVersion.V2;
- First, make projections available using the URI.
- For more information’s regarding this subject read this post from the Product Team.
Feed Customizations are the possibility to customize the way the feed is created instead of using only the default AtomPub version.
- In order to achieve this customization we must use the EntityPropertyMappingAttribute that will define the relationship between the Property and the name that will be used in the feed.
In the following sample we are defining that when building the feed, instead of using the complete type definition
1: <author>2: <name>Nuno Godinho</name>3: <email>someone@company.com</email>4: </author>
we will have the Author element with the value that is on the Name Property of the Author class (considering that Author is a type that contains several properties and one of them is Name):
and so the result will be:1: [EntityPropertyMapping(2: "Author",/*Source property path , the property of the Entity type to be mapped*/3: SyndicationItemProperty.AuthorName,/* Syndication item to which the Source Property is mapped*/
4: SyndicationTextContentKind.Plaintext,/* Syndication content kind for the syndication item this property is bound to */
5: true/* If false the property value is only placed at the mapped location & removed from the <content> section of the atom:entry*/6: )]
For more information's regarding this customization read the following posts:1: <author>Nuno Godinho</author>
Introducing Web Friendly Feeds aka Friendly Feeds (Updated for CTP2)
ADO.NET Data Services Friendly Feeds , Mapping CLR Types
ADO.NET Data Services Friendly Feeds , Mapping EDM Types – I
Data Binding is now simplified, because using the DataServiceCollection class we can bind it directly to the Data Service.
- For more information’s regarding this subject read this post from the Product Team.