This project is read-only.

Instructions

1. In Visual Studio, create proxy class to a OData service.
2. Create a parameterless constructor for the proxy class.
Sample
//Adding parameterless constructor
public partial class EventEntities
{
  public EventEntities(): this(new Uri("http://api.visitmix.com/OData.svc"))
  {
  }
}
//Adding parameterless constructor
public partial class CustomContext
{
  // It builds a relative address to OData Service in the same web.
  private static Uri CreateURI()
  {
    Uri res = null;
    if(System.ComponentModel.DesignerProperties.IsInDesignTool) {
      res = new Uri("http://localhost/test.svc"); //Design mode. Constructor needs some URL.
    } else {
      int idx = App.Current.Host.Source.AbsoluteUri.IndexOf("/ClientBin");
      res = new Uri(App.Current.Host.Source.AbsoluteUri.Substring(0, idx) + "/CustomService.svc");
    };
    return res;
  }
  //Constructor
  public CustomContext() : this(CustomContext.CreateURI())
  {
  }
}
3. You can add display attributes and validation rules.
Sample
namespace Demo.OData.CustomService
{
  //Entity class
  public partial class Product
  {
    internal class Metadata
    {
      [Key]
      [Editable(false, AllowInitialValue = true)]
      public global::System.Guid ProductID { get; set; }

      [Display(Name = "product_name", ResourceType = typeof(Demo.OData.LangResources.LocalizedStrings))]
      [Required(), StringLength(50, MinimumLength = 3)]
      public string Name { get; set; }

      [Display(Name = "product_poductnumber",ResourceType=typeof(Demo.OData.LangResources.LocalizedStrings))]
      [Required(), StringLength(50, MinimumLength = 3)]
      public string ProductNumber { get; set; }

      [Display(Name = "product_size", ResourceType = typeof(Demo.OData.LangResources.LocalizedStrings))]
      [Range(0, 100)]
      public int Size { get; set; }

      [Display(Name = "product_color", ResourceType = typeof(Demo.OData.LangResources.LocalizedStrings))]
      public string Color { get; set; }

      [Display(Name = "product_standardcost", ResourceType = typeof(Demo.OData.LangResources.LocalizedStrings))]
      public decimal StandardCost { get; set; }
    
      [Display(Name = "product_listprice", ResourceType = typeof(Demo.OData.LangResources.LocalizedStrings))]
      public decimal ListPrice { get; set; }
      
      [Display(Name = "product_weight", ResourceType = typeof(Demo.OData.LangResources.LocalizedStrings))]
      public decimal Weight { get; set; }
      
      [Display(Name = "product_sellstartdate", ResourceType = typeof(Demo.OData.LangResources.LocalizedStrings))]
      public DateTime SellStartDate { get; set; }
    }
  }
}
4. Create your XAML form.
Sample
<navigation:Page 
  xmlns:mac="clr-namespace:System.Windows.Controls;assembly=Slma.Windows.Controls"
  xmlns:mao="clr-namespace:System.Windows.Controls;assembly=Slma.Windows.Controls.OData"
  xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"						 
  xmlns:od="clr-namespace:System.Windows.Controls;assembly=Slma.OData"
  xmlns:service="clr-namespace:Demo.OData.CustomService"
  xmlns:local="clr-namespace:Demo.OData"
  xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
<Grid x:Name="LayoutRoot" DataContext="{Binding ElementName=dsProducts, Path=Data}">
   <od:ODataSource 
      x:Name="dsProducts" 
      EntitySetName="Products" >
      <od:ODataSource.DataServiceContext>
        <service:CustomContext />
      </od:ODataSource.DataServiceContext>
      <od:ODataSource.SortDescriptions>
        <od:SortDescriptionOData  PropertyName="Name" Direction="Ascending"  />
      </od:ODataSource.SortDescriptions>
   </od:ODataSource>

   <toolkit:DataForm  
          Margin="0,10,0,0" Header="Product detail" 
          AutoEdit="False" AutoCommit="False" 
          ItemsSource="{Binding Path=Data, ElementName=dsProducts}">
   </toolkit:DataForm>

    <mac:WaitControl IsBusy="{Binding ElementName=dsProducts,Path=IsBusy,Mode=OneWay}"  />
  </Grid>
</navigation:Page>
Master-detail
    <!--data source-->
    <!--SESSIONS-->
    <od:ODataSource 
      x:Name="dsSessions" EntitySetName="Sessions" AutoLoad="True" 
      CurrentItemChanged="dsSessions_CurrentItemChanged"
      >
      <od:ODataSource.DataServiceContext>
        <service:EventEntities />
      </od:ODataSource.DataServiceContext>
      <od:ODataSource.SortDescriptions>
        <od:SortDescriptionOData  PropertyName="StartTime" Direction="Ascending"  />
      </od:ODataSource.SortDescriptions>
    </od:ODataSource>
    <!--SPEAKERS-->
    <od:ODataSource 
      x:Name="dsSpeakers" EntitySetName="Speakers" AutoLoad="False" ForeignKey="{Binding ElementName=dsSessions, Path=CurrentPrimaryKey}"  
      LoadSize="99" IncludeTotalCount="False"
      >
      <od:ODataSource.DataServiceContext>
        <service:EventEntities />
      </od:ODataSource.DataServiceContext>
    </od:ODataSource>
    <!--Files-->
    <od:ODataSource 
      x:Name="dsFiles" EntitySetName="Files" AutoLoad="False" ForeignKey="{Binding ElementName=dsSessions, Path=CurrentPrimaryKey}" 
      LoadSize="99" IncludeTotalCount="False"
      >
      <od:ODataSource.DataServiceContext>
        <service:EventEntities />
      </od:ODataSource.DataServiceContext>
    </od:ODataSource>

Last edited Sep 9, 2010 at 6:52 PM by MirekM, version 28

Comments

No comments yet.