RIA Service For DataBinding To PieChart in silverlight 4
How to create RIA Domain Service for databinding to pie chart with dependentpath and independentpath value in silverlight 4?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Soft CornerPosted Jul 14, 2011, 5:30 AM
For creating Ria Domain Services you will need :
1. Add 2 references
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server;
2. to access domain service add attribute above class name
[EnableClientAccess()]
The following is the Employee Domain Service which will return a list of employees
[EnableClientAccess()]
public class EmployeeDomainService : DomainService
{
public List
{
List
EmployeeDTO employee = new EmployeeDTO();
employee.ID = 1;
employee.FirstName = "Jason";
employee.LastName = "Apergis";
employees.Add(employee);
employee = new EmployeeDTO();
employee.ID = 2;
employee.FirstName = "Ethan";
employee.LastName = "Apergis";
employees.Add(employee);
employees.Add(employee);
return employees;
}
}
for Accessing service from client side, add namespace of web part and then access:
private EmployeeDomainContext _context = null;
public EmployeeViewModel() //constructor of client
{
_context = new EmployeeDomainContext();
_context.Load(_context.GetEmployeesQuery());
}
Like this you can return values for Pie Chart for binding too.
Priya LingePosted Jul 14, 2011, 6:23 AM
For Creating Ria DomainService ,Please follow the below steps,
Step 1> Suppose Your Silverlight Application Project let say RiaDomainSevices . Now right Click on your Web Project and select "Add New Item", Select "Data" from the Tree Menu on the Left, and then Select "ADO.NET Entity Data Model".Select table data which you want,then build your web project after that select "Add New Item", Select "Web" from the Tree Menu on the Left, and then Select "Domain Service Class".You will get Domain Service which you created.
Here you will get below assemblies by default, Please make those dll Copy Local to true by selecting their property.
using System.ServiceModel.DomainServices.EntityFramework;
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server;
Bulid your Domain service,then add below assemlies reference in your page.xaml.cs.
using System.ServiceModel.DomainServices.Client;
using RiaDomainSevices.Web;
by adding this you will get your DomainContext let say ,
private CustomerDomainContext _context = new CustomerDomainContext();
_context.Load(_context.GetCustomersQuery());
dataGrid1.ItemsSource = _context.Customers;
like this you can bind your data,For piechart make one class in Domainservice.cs,
public class Customer
{
public Customer()
{
[Key]
public string Name { get; set; }
public int ID{ get; set; }
}
you can bind name and id to pie chart,
<toolkit:PieSeries x:Name="pieText" DependentValuePath="{Binding Name}" IndependentValuePath="{Binding ID>toolkit:PieSeries> toolkit:Chart>
When you will going to use Domain services,at that time you will face some error for e.g.
Domain service Exception errors .
An error occurred while loading data through the 'GetStreetNames' query on DomainContext of type 'PatriotDomainContext' and the error was not handled.
For these errors, please see the below links.
http://forums.silverlight.net/forums/p/173862/391495.aspx
http://forums.silverlight.net/forums/p/203848/476896.aspx
For Creating Ria Domain Services.
http://www.adam-thompson.com/category/Silverlight-4.aspx
http://msdn.microsoft.com/en-us/library/ee707376(v=vs.91).aspx
Thanks.