Recently, we came across a bug with the Silverlight Business Application with respect to an Out of Browser application. In the RTM bits for Silverlight 4 Tools a new feature was added to enable a better debugging experience with Out of Browser application. The feature basically launched the app in OOB window when run with the debugger attached. If you have tried that with the business application template, you will notice that the app does not run. It crashes with an exception, that the URI path is not valid.
We realize this is an issue most folks are running into and we have fixed this template and we are looking ways to get you access to it. However, there is a relatively easy workaround to fix this issue.
The steps involved are :-
Cheers!!
Earlier I had posted about the theme pack for the Silverlight Business Application and amongst them was the Cosmopolitan template. The cosmopolitan theme is inspired by the Metro theme which was first seen in the the Zune Client.
Since then, there have been many variations of the Metro theme, Windows Phone 7, Metrotwit, the Cosmopolitan theme and many more. They are all inspired by the Metro theme. Recently, Nikola. pointed out one of the key differences between the Zune client and the Cosmopolitan theme. One thing, I would like to call out is that they are just different variations. However, I do understand that there is a demand to create a app that looks and feels like the Zune client and in this post I will show you how that can be done using the Cosmo theme.Thanks Tsitsi for your help. She is also the designer that created these designs. I would definitely recommend subscribing to her blog. First download and install the theme pack, the instructions can be found here.
Let’s start of by creating a Silverlight Business application Cosmopolitan template. Once that is created, follow these steps:-
1: <my:Double x:Key="ApplicationNameFontSize">20</my:Double>
2: <my:Double x:Key="HeaderFontSize">21.333</my:Double>
3: <my:Double x:Key="NavigationFontSize">20</my:Double>
<!-- ApplicationName Style -->
<Style x:Key="ApplicationNameStyle" TargetType="TextBlock">
<Setter Property="Foreground" Value="{StaticResource BlackBrush}"/>
<Setter Property="FontFamily" Value="{StaticResource ContentFontFamily}"/>
<Setter Property="FontSize" Value="{StaticResource ApplicationNameFontSize}"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="TextOptions.TextHintingMode" Value="Animated" />
<Setter Property="Margin" Value="32,-4,0,-3"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
</Style>
<!-- Links Border Style -->
<Style x:Key="LinksBorderStyle" TargetType="Border">
<Setter Property="Height" Value="40"/>
<Setter Property="Margin" Value="0,32,10,0"/>
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="BorderBrush" Value="{StaticResource HighlightBrush}"/>
<Setter Property="BorderThickness" Value="14,0,0,0"/>
<!-- Links StackPanel Style -->
<Style x:Key="LinksStackPanelStyle" TargetType="StackPanel">
<Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="Orientation" Value="Horizontal"/>
<Setter Property="Margin" Value="10,0,0,-7"/>
<!-- Logo Icon Style -->
<Style x:Key="LogoIcon" TargetType="ContentControl">
<Setter Property="Height" Value="30"/>
<Setter Property="Width" Value="35"/>
<Setter Property="Margin" Value="0,0,53,0"/>
<Setter Property="HorizontalAlignment" Value="Right" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContentControl">
<Grid>
<Rectangle Fill="{StaticResource HighlightBrush}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<!-- Content Frame Style -->
<Style x:Key="ContentFrameStyle" TargetType="navigation:Frame">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Margin" Value="0,75,0,0"/>
<Setter Property="Padding" Value="30,15,58,15"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<!-- Branding Border Style -->
<Style x:Key="BrandingBorderStyle" TargetType="Border">
<Setter Property="Height" Value="Auto"/>
<Setter Property="Margin" Value="0,0,20,10"/>
<Setter Property="VerticalAlignment" Value="Top"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
The end result of these changes will be an application that looks like the Zune Client. Here is a screenshot:-
Cheers and enjoy!!
At Teched 2010, we announced the RTM of Windows Server AppFabric. I am sure most of you are wondering what Windows Server AppFabric is?
Windows Server AppFabric is a set of integrated technologies that make it easier to build, scale and manage Web and composite applications that run on IIS. You can install and read more about it here. Also, check out the white paper located here. One of the component that Windows Server AppFabric provides is the monitoring AppFabric dashboard in IIS.
The app fabric dashboards lets you monitor any .NET 4 WCF an WF services with monitoring enabled. As you are all aware that a Domain Service is a WCF service and one of the things we enabled in our RTM build was to enable monitoring for the DomainService. However, this will only work when the web application is hosted in full trust.
Check out this episode on EndPoint.tv for more deatils
Endpoint.TV – Windows Server AppFabric in action monitoring and troubleshooting
Enabling AppFabric monitoring for a domain service is very easy. Here is what you would need to do:-
1: <system.serviceModel>
2:
3: <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
4:
5: <serviceActivations>
6: <add service="MSTravel.Web.Services.TailSpinTravelService" factory="System.ServiceModel.DomainServices.Hosting.DomainServiceHostFactory, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" relativeAddress="~/Services/MSTravel-Web-Services-TailSpinTravelService.svc" />
7: <add service="MSTravel.Web.AuthenticationService" factory="System.ServiceModel.DomainServices.Hosting.DomainServiceHostFactory, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" relativeAddress="~/Services/MSTravel-Web-AuthenticationService.svc" />
8: <add service="MSTravel.Web.UserRegistrationService" factory="System.ServiceModel.DomainServices.Hosting.DomainServiceHostFactory, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" relativeAddress="~/Services/MSTravel-Web-UserRegistrationService.svc" />
9: </serviceActivations>
10:
11: </serviceHostingEnvironment>
12:
13: </system.serviceModel>
You can use the AppFabric dashboard to monitor and track the usage of your DomainService. As you can see it gives you all the error and completed tracked events.
Cheers and Enjoy!!
Last week, we released theme packs for Silverlight Application Templates along with some cool looking themes for the Silverlight Business Application. Download the refreshed Silverlight 4 themes (inlcuding RIA Services templates) here.
Notes: Courtesy of Tim
At the link above you’ll find 3 files to download:
The three templates we released are :-
Cosmopolitan:-
See it in action here:- http://www.silverlight.net/content/samples/sl4/themes/cosmopolitan.html#/Home
Windows 7 Theme:
See it in action here:- http://www.silverlight.net/content/samples/sl4/themes/windows7.html#/Core
Accent Color Theme:
See it in action here:-http://www.silverlight.net/content/samples/sl4/themes/accent.html
These application make the Silverlight Business Application Template just awesome.
As promised, I am uploading the source code for the demo. Please keep in mind, there are some places where I have not followed best practices, I will follow up with a post after finishing and cleaning up the application. I have had a bunch of folks ask about the source code, so I wanted to get it out there.
You can download the source here:-
http://cid-9d24497f7fef8f33.office.live.com/self.aspx/Demo/TechEd%202010%20-%20Web%20307.zip
Steps:
Note: If you encounter an error when running the application, just run the application again.
Check out the admin page where, i create one screen that modifies 8 Lookup Tables. You can do as many as you want.
Also, check out the Tips page to recap the Tips we covered in the talk.
I will follow up with a more detailed post with details and steps.
It’s been a great week at TechEd North America 2010 in New Orleans. There is a very good reason why they call it the Big Easy and now I know:)
I was really surprised to see the number of folks that came out there and really glad to see the response RIA Services got . I was at the Silverlight booth most of the time and it was just amazing seeing so many questions from so many different people. Its just great to know that so many folks are using our product.
I had the opportunity to talk at three different occasion during TecheEd, I did a short demo in the JasonZ Developer Foundation Sessions, then i had an interactive session where I talked about accessing web services in Silverlight.
Here are the recordings for those sessions:-
Foundations session by Jason Zander. My demo is around the 43 min mark
Interactive Session ( will update it )
Breakout Session: WEB 307 – Effective RIA: Tips and tricks for building Rich Internet Application
I have not had the chance to clean up the source code for all the demos. I will follow up with the code for most of them soon. Stay Tuned!!
I recently recorded a Silverlight TV episode where I demoed configuring a RIA Services DomainService to expose SOAP, JSon and OData endpoints. The video went online earlier today and it can be found here.
Oh and be sure to check out for Silverlight TV Episode 28. It’s going to be awesome!! Stay Tuned!
As you all are aware, RIA Services has a great story OM and tooling story for Silverlight.What if you want a mobile application talking to a domain service or an Ajax application? There could be various different reasons why one would want to expose a different endpoint. The great thing is that enabling these endpoints requires minimal changes in your application.
You will need the following components:-
The OData endpoint support is provided out of the box for you. Here is how you can expose an OData Endpoint.
1: [Query(IsDefault=true)]
2: public IQueryable<Book> GetBooks()
3: {
4: return this.ObjectContext.Books.OrderBy(b => b.Title);
5: }
1: <configSections>
2: <sectionGroup name="system.serviceModel">
3: <section name="domainServices"
4: type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection,
5: System.ServiceModel.DomainServices.Hosting,
6: Version=4.0.0.0, Culture=neutral,
7: PublicKeyToken=31BF3856AD364E35"
8: allowDefinition="MachineToApplication"
9: requirePermission="false" />
11: </sectionGroup>
12: </configSections>
13:
1: <domainServices>
2: <endpoints>
3: <add name="OData"
4: type="System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory, System.ServiceModel.DomainServices.Hosting.OData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
5: </endpoints>
6: </domainServices>
7:
NOTE: The ODATA endpoint has very limited support in V1. There is no Update or LINQ query support in this release.
In my earlier post, I had showed how to configure a domain service for a Windows Phone 7 application. In that post I had used the Soap endpoint. Configuring a soap and JSON endpoint needs the RIA Services toolkit. After you have installed the toolkit, you will need to do the following:-
3:
4: <add name="OData"
5: type="System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory, System.ServiceModel.DomainServices.Hosting.OData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
6:
7: <add name="soap"
8: type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
9:
10: <add name="JSON"
11: type="Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
13: </endpoints>
14: </domainServices>
Note: You can use SOAP and Json endpoints to submit.
A domain service is a WCF Service; therefore it has a SVC path. You can now access the three endpoint we exposed using that.
The uri for these endpoints are:-
OData :http://localhost:[portnumber]/[SLprojectName]-Web-[DomainsServiceName].svc/OData/
SOAP: http://localhost:[portnumber]/[SLprojectName]-Web-[DomainsServiceName].svc
JSON: http://localhost:[portnumber]/[SLprojectName]-Web-[DomainsServiceName].svc/JSON/
With these exposed endpoints, you can talk to multiple clients. In the episode above, I used the following clients:-
You can download the source code for the demo from here.
Teched 2010 is almost around the corner. It will be held in New Orleans LA from June 7-10. Details and schedule of talks are now published online. I will be attending the conference this year and will actually be giving two talks. The first one as you must have guessed is on RIA Services. Below are the details
WEB307 | Effective RIA: Tips and Tricks for Building Effective Rich Internet Applications
Maintainability, testability, performance, and security can be improved by understanding the components and tools and following some basic guidelines. This session uses Windows Communication Foundation RIA Services and Microsoft Silverlight as the key tools and covers the separation of concerns between data access, logic and presentation tiers, best practices for testability and tricks for getting better performance through design. We also cover best practices for locking down your application
Rich Internet Applications (RIAs) rely on platforms such as Silverlight and Windows Phone 7 to present data to users in an interesting and interactive manner. With Windows Communication Foundation (WCF) 4, developers can use a unified programming model for accessing services and data in any Microsoft .NET Framework-based application – including RIAs. This session explores how you can leverage your WCF skills along with rich tooling to build distributed services for the RIA. This talk rationalizes the use case for WCF RIA Services, but focuses mostly on innovations in the core WCF feature set. The talk also shows how WCF simplifies talking to web2.0 services like Bing, REST based service. Also, learn how to build a WCF backend service that enables rich and high performance messaging to RIA Clients like a video chat. By the end of this session you will understand some of the powerful architectures available to you for building RIAs with WCF.
At Mix 2010, Nikhil tried something different where he had asked the community of the things they would like to see. I really liked that approach and I am looking to follow a similar idea for my talk.
So, what would you like to see covered? I will definitely try to add it to my demo, if it fits in the overall theme and flow. So please share your thoughts here or email me.
Looking forward to seeing all of you at Teched in the Big Easy and looking to hear your thoughts on the talk and things you would like to see.
Last Thursday, we released our RC2 build of RIA Services. You can download all the latest bits from http://silverlight.net/riaservices
These set of bits are compatible with Silverlight 4 RTM and Visual Studio 2010 RTM. I am sure most of you are wondering, why not RTW RIA Services already. Trust me, we would love to release this baby as soon as possible, we are pretty much done. However, we have dependencies on other components. We just need to do the extra bit of testing against these bits to ensure things work fine.
Last week I got to attend DevConnections and was on Channel 9 talking about RIA Services. You can watch it here Watch Ch9 Live on demand!. My RIA Services segment is at the 2hr and 15 min mark. I talk about our dependencies. Also, be sure to check out the RIA Services book club app in the Silverlight 4 launch keynote. Watch the keynote on demand!
I know most of you have been asking what new in this version of RIA Services. As the name suggests this is a Release Candidate 2 and there aren’t any new features. However, this release has tons of bug fixes and community reported issues. Here are some of the the changes (some taken from Dinesh’s Post):-
We would love to hear your feedback so be sure to get back to us via forums, twitter etc.
Cheers
One of things that came up repeatedly in our API Reviews for RIA Services was the fact that, we were requesting the total server count of the resulting query by default for paging scenarios.
This basically meant that were executing two queries on the database:-
This was never an issue for most non-paging scenarios as the framework was optimized for it. Here is the flow in the previous releases:-
1: loadOp = ds.Load<Customer>(ds.GetCustomersQuery());
2: loadOp.Completed += new EventHandler(loadOp_Completed);
The count for this query would by 91 entities and the total entity count will also be 91 (No of customers in Northwind database).
In the latest RIA Services bits, we made a change where the count is not returned by default for paging scenarios.
Running a query like the one specified above will not have affect on the count and only one query will be executed on the server.
Now let’s modify the query to look like this and run it on the RC bits:-
loadOp = ds.Load<Customer>(ds.GetCustomersQuery().Take(10));
loadOp.Completed += new EventHandler(loadOp_Completed);
Now let’s look at the count returned from the server:-
As you can see the TotalEntityCount is –1.
So now the question arises is that how do i get the count when i add a take. All you need to do is to set the IncludeTotalCount property to true on the EntityQuery. Here is an example to do that:-
EntityQuery <Customer>loadCustomers = ds.GetCustomersQuery();
loadCustomers.IncludeTotalCount= true;
loadOp = ds.Load<Customer>(loadCustomers.Take(10));
Here are the results:-
DomainDataSource has been optimized to take this change into account and it will not request for count in non-paging scenarios. As soon as a page size is specified, DomainDataSource will set the IncludeTotalCount property on the EntityQuery for you. You can always override this behavior by subscribing to the LoadingData event on the DomainDataSource.
Cheers!
At Mix 2010, ScottGu talked about the developer story of Windows Phone 7. As you know by now, that the developer story is on Silverlight. I have also seen some questions regarding Windows Phone and whether RIA Services can be used part in it.
Unfortunately, there is no in built support for the Mobile platform in RIA Services V1.0. I know that is a big bummer because every Silverlight developer is now a windows phone developer. Rest assured we do think RIA Services support for Windows Phone is very important, but it will not make it in our V1.0.
With that said, you can still enable a Windows Phone 7 application to communicate with a DomainService and here is how…
At PDC 09, we made a big change, where every DomainService is now a WCF Service. Windows Phone 7 has support for talking to a WCF Service and we can leverage that to our advantage and create a mobile application that talks to a domain service. Yes, you do not get the rich client experience RIA Services provides for Silverlight, but you still get all the benefits of the server richness in the V1 release.
Here is how you would do that:-
I am going to skip over the section on how to create a domain service. You can find that at @brada’s post about exposing data from entity framework. Next we are going to configure the domain service to expose a soap endpoint.
Now that you have have a DomainService configured, we are going to configure it to expose a soap endpoint. In the PDC preview bits this was exposed by default, but we have now scaled that back for various reason. In the RC release you would need to configure your DomainService to be exposed as a WCF Soap Endpoint. Here is how you would do that (assuming you have created a domain service already):-
3: <domainServices>
4: <endpoints>
5: <add name="soap" type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
6: </endpoints>
7: </domainServices>
3: <section name="domainServices" type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
4: </sectionGroup>
5: </configSections>
Now that we have configured our DomainService to expose a SOAP endpoint, we can now write a Windows Phone application that talks to it.
1: public override string ToString()
2: {
3: return LastName+", "+FirstName +" Title: " +Title;
4: }
1: public void LoadEmployee()
3: ServiceReference1.DomainService1soapClient client = new ServiceReference1.DomainService1soapClient();
4: client.GetEmployeesCompleted += new EventHandler<ServiceReference1.GetEmployeesCompletedEventArgs>(client_GetEmployeesCompleted);
5: client.GetEmployeesAsync();
7: }
8:
9: void client_GetEmployeesCompleted(object sender, ServiceReference1.GetEmployeesCompletedEventArgs e)
10: {
11: this.listBox1.ItemsSource = e.Result.RootResults;
12: }
There is a very good sample posted at our code gallery site, that explains how you can do CRUD operation with the SOAP endpoint of a DomainService. You can find it here.
Server throttling is one the new features we introduced in our RC release. It lets you regulate the per request load on the server / DB by specifying maximum result limit on a query method using the QueryAttribute.ResultLimit property.
Here is how you can specify a result limit on a query method:-
1: [Query(ResultLimit=1000)]
2: public IQueryable<Customer> GetCustomers()
4: return this.ObjectContext.Customers;
The result limit query only applies to the top level entities, so the above query will result in returning 1000 top level entities. This limit will not apply to the included entities.
As you will notice, the ResultLimit will not be propagated to the client. Things get really interesting when you use DomainDataSource especially when you are using LoadSize and PageSize.
Keep the following in mind, if you are developing an application that happens to have a query limit and uses DomainDataSource on the client:-
Here is an example on how to specify LoadSize and PageSize on DomainDataSource
1: <riaControls:DomainDataSource
2: AutoLoad="True"
3: LoadSize="20"
4: PageSize="10"
5: Name="customerDataDomainDataSource"
6: QueryName="GetCustomersQuery"
7: Width="0">
8: <riaControls:DomainDataSource.DomainContext>
9: <my:CustomerContext/>
10: </riaControls:DomainDataSource.DomainContext>
11: </riaControls:DomainDataSource>
Hosting servers generally do not have Visual Studio 2010 or Silverlight SDK installed, this might be a blocker for some hosting companies.
The RIAServices msi now has a command line override, especially for hosters. The msi is now configured to take a “Server” command line parameter that will only check for .NET Framework 4.0. The command line parameter will install all the RIA Services server assemblies.
Here is how to use this option:-
1: msiexec /i RIAServices.msi SERVER=true
Using this option will do the following, install the server assemblies along with adding them to the Global assembly cache and to the native cache (ngen).
Keep in mind, using this option will not install any of the Silverlight or Tooling components.
BTW here are some of the hosters that will be supporting RIA Services:-
DiscountASP - http://labs.discountasp.net/
OrcsWeb - http://vs2010host.com/
ASPHostCentral - http://asphostcentral.com/
The RIA Services team just released the RC version of the product. You can find all the installation instruction @ http://silverlight.net/RIAServices.
I am going to talk about the features have been added to this release and also introduce you to the RIA Services Toolkit.
You can download the RIA Services Toolkit here.
We have added some great features since the PDC 09 release. We have heard all the feedback and tried to address some of the important ones. The list is taken from Dinesh’s forum post. Trust me there have been a lot more additions than the one listed below. I will follow up with more posts or updated links for each feature.
INDEI Support:- Validation support based on Silverlight 4’s INotifyDataErrorInfo. This is a non-exception-based model and enables async validations more easily. It also helps display errors flagged by the server in the UI.
Spiffier DDS: filter/sort/group descriptors support binding; ICommand support for Load/SubmitChanges/RejectChanges
Server throttling: you can regulate the per request load on the server / DB by specifying maximum result limit on a query method using the QueryAttribute.ResultLimit property.
AuthorizationContext: Similar to ValidationContext, now you have more options for implementing custom authorization rules (e.g. entity-based authorization)
Endpoint configuration support: Following the “secure by default” principle, only binary endpoint will be exposed but we have made it really easy to add additional/different endpoints if you plan to use them.
OData endpoint: you can point PowerPivot to a DomainService OData endpoint and analyze data by calling the appropriate query method. This is the first step in lighting up OData with RIA Services.
Along with these features in the main product, we are also announcing the availability of new package called the RIA Services Toolkit
The WCF RIA Services Toolkit is a collection forward looking features made available outside the normal RIA Services release cycle. A product of the WCF RIA Services product team, the Toolkit adds new functionality quickly for developers and provides the community an efficient way to help shape product development by contributing ideas and bug reports.
The following functionality are available in this release of the Toolkit:
You can find the breaking changes document here.
There is quite a bit to play with here and we would love to hear your feedback. You can reach to us at http://forums.silverlight.net/forums/53.aspx
Earlier this week we released the Beta version of WCF RIA Services for Visual Studio 2008 and the preview version for VS2010 Beta 2. There were a lot of great features added to it from our July CTP.
Here is a quick list of all the features:-
You can get details for most of them from http://silverlight.net/riaservices.
One of the features that I got to work on was the Presentation Model.
So what is presentation model in WCF RIA Services?
Exposing DAL types back to client is not a good idea in many ways. The system can go through many changes and can move away from a particular backend to another. This change will require the client to be updated which can be costly. Application developers also have the desire to control what the entity looks like on the client. To address some of these concerns application developers have been adapting the Data Transfer Objects pattern but that does not fit well with RIA services as we have a notion of Domain Object Model where the user can write custom Business Logic. Enters WCF RIA Services presenttion model.
During the design phase of the feature, we were looking to enable four main scenarios:-
In this post I will try to cover up on how you can achieve the top three scenarios, I will follow up with a more detailed post on how to propagate errors back to the client.
In this blog post I will be using the following DAL Types:-
I will create the following PresentationModel type and project to the client:-
In order to create a Presentation Model type you will need to create a new POCO(Plain OLD CLR Object) type in the server project.
Add this type to your server project.
public class PM_Customer
{
[Key]
public int CustomerID { get; set; }
public string Email { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string FavoriteColor { get; set; }
public string SomeOtherPreference { get; set; }
public string City { get; set; }
public string State { get; set; }
public int Zip { get; set; }
}
Projecting Presentation Model type to the client
Converting DAL type to presentation model types will be a typical scenario for query methods. An application developer can use projection to compose his presentation model type. The code for querying presentation model type would look like:-
public IQueryable<PM_Customer> GetCustomers()
return from c in this.Context.DAL_CustomerSet
select new PM_Customer()
CustomerID = c.CustomerID,
Email = c.EmailAddress,
City = c.CustomerProfile.City,
FavoriteColor = c.CustomerPreferences.FavoriteColor,
FirstName = c.FirstName,
LastName = c.LastName,
SomeOtherPreference = c.CustomerPreferences.SomeOtherPreference,
State = c.CustomerProfile.State,
Zip = c.CustomerProfile.ZipCode
};
Updating DAL types from Presentation Model types
Converting presentation model type to DAL types will be a typical scenario for update or custom methods. An application developer can use projection to compose his presentation model type. The code for updating presentation model type would look like:-
[Update]
public void UpdateCustomer(PM_Customer customer)
DAL_Customer dalCustomer = this.Context.DAL_CustomerSet.Where(c => c.CustomerID == customer.CustomerID).FirstOrDefault();
DAL_CustomerPreferences dalPreferences = this.Context.DAL_CustomerPreferencesSet.Where(c => c.CustomerID == customer.CustomerID).FirstOrDefault();
DAL_CustomerProfile dalProfile = this.Context.DAL_CustomerProfileSet.Where(c => c.CustomerID == customer.CustomerID).FirstOrDefault();
// Custom logic to copy data from PM type to DAL Type
this.MyMerge(customer, dalCustomer);
this.MyMerge(customer, dalPreferences);
this.MyMerge(customer, dalProfile);
In this example MyMerge is a custom function that I wrote which copies values from my presentation model type to my DAL Type. You can choose to do the merge in place.
Updating Presentation Model types after submit changes.
Many databases design have fields that are store generated value. E.G. timestamps, ids etc. To flow back these values to the client a developer would need to do the following.
this.ChangeSet.Associate(customer, dalCustomer, MapDALCustomerToPMCustomer);
this.ChangeSet.Associate(customer, dalPrefernces, MapDALCustomerToPMCustomer);
this.ChangeSet.Associate(customer, dalProfile, MapDALCustomerToPMCustomer);
The change set will now have a new function called the Associate which will take in instances of PM Type and DAL Types. Once the data is submitted to the database the MapDALCustomerToPMCustomer function will be called with the updated instances.
private void MapDALCustomerToPMCustomer(PM_Customer pmCustomer, DAL_Customer dalCustomer)
pmCustomer.CustomerID = dalCustomer.CustomerId;
I could set up transform function for each of my DAL Types and flow back the value in to my Presentation Model type and then to the client.
This post should get you started on presentation model type. I will follow up with a post on how to flow back errors to the client.
Earlier in the year, BradA had started this tradition. Each week he would round up links from across the web on RIA Services. I really loved that idea and have decided to continue the tradition.
Before I get started, here is a little about me:-
I am a Program Manager on the RIA Services team and have been working on it for the past 18 months now. These months have been the most enjoyable during my short tenure in Microsoft (~ 4.5 years). Prior to joining the RIA Services team, i was working on various other products from Microsoft like Windows Forms, Click Once and BizTalk Server. My team was responsible bringing the Developer Tools for BizTalk Server.
Anyways let me not bore you with my bio.
Here are some useful links about RIA Services
The links above are useful to follow and to get an update about RIA Services.
Here are some blog entries by some colleagues of mine and by community that illustrate the power of RIA Services:-
Stay Tuned for more links in the coming days...
Oh and how about them Colts and Saints....8-0 Baby!!!