Click here to Skip to main content
15,896,526 members
Articles / Web Development / CSS

Building a 3-Tier App with Silverlight 3, .NET RIA Services, and Azure Table Storage

Rate me:
Please Sign up or sign in to vote.
4.89/5 (28 votes)
11 Jul 2009CDDL19 min read 165.9K   1.7K   148  
This article presents the techniques and caveats of building a 3-tire Azure hosted application using Silverlight 3 (presentation tier), .NET RIA services (business logic and data access), and Windows Azure Table (data storage).
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.4016
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Hanray.Azurelight
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Web.Ria.Data;
    using System.Windows.Ria.Data;
    
    
    /// <summary>
    /// Context for the RIA application.
    /// </summary>
    /// <remarks>
    /// This context extends the base to make application services and types available
    /// for consumption from code and xaml.
    /// </remarks>
    public sealed partial class RiaContext : System.Windows.Ria.RiaContextBase
    {
        
        #region Extensibility Method Definitions

        /// <summary>
        /// This method is invoked from the constructor once initialization is complete and
        /// can be used for further object setup.
        /// </summary>
        partial void OnCreated();

        #endregion
        
        
        /// <summary>
        /// Initializes a new instance of the RiaContext class.
        /// </summary>
        public RiaContext()
        {
            this.OnCreated();
        }
        
        /// <summary>
        /// Gets the context that is registered as a lifetime object with the current application.
        /// </summary>
        /// <exception cref="InvalidOperationException"> is thrown if there is no current application,
        /// no contexts have been added, or more than one context has been added.
        /// </exception>
        /// <seealso cref="Application.ApplicationLifetimeObjects"/>
        public new static RiaContext Current
        {
            get
            {
                return ((RiaContext)(System.Windows.Ria.RiaContextBase.Current));
            }
        }
    }
}
namespace Hanray.Azurelight.Model
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.Web.Ria.Data;
    using System.Windows.Ria.Data;
    
    
    [DataContract(Namespace="http://schemas.datacontract.org/2004/07/Hanray.Azurelight.Model")]
    public sealed partial class Survey : Entity
    {
        
        private string @__eTag;
        
        private string _comments;
        
        private string _partitionKey;
        
        private Nullable<int> _rating;
        
        private string _rowKey;
        
        private string _target;
        
        private DateTime _timestamp;
        
        #region Extensibility Method Definitions

        /// <summary>
        /// This method is invoked from the constructor once initialization is complete and
        /// can be used for further object setup.
        /// </summary>
        partial void OnCreated();
        partial void On_ETagChanging(string value);
        partial void On_ETagChanged();
        partial void OnCommentsChanging(string value);
        partial void OnCommentsChanged();
        partial void OnPartitionKeyChanging(string value);
        partial void OnPartitionKeyChanged();
        partial void OnRatingChanging(Nullable<int> value);
        partial void OnRatingChanged();
        partial void OnRowKeyChanging(string value);
        partial void OnRowKeyChanged();
        partial void OnTargetChanging(string value);
        partial void OnTargetChanged();
        partial void OnTimestampChanging(DateTime value);
        partial void OnTimestampChanged();

        #endregion
        
        
        /// <summary>
        /// Default constructor.
        /// </summary>
        public Survey()
        {
            this.OnCreated();
        }
        
        [DataMember()]
        [Display(AutoGenerateField=false)]
        public string _ETag
        {
            get
            {
                return this.@__eTag;
            }
            set
            {
                if ((this.@__eTag != value))
                {
                    this.ValidateProperty("_ETag", value);
                    this.On_ETagChanging(value);
                    this.RaiseDataMemberChanging("_ETag");
                    this.@__eTag = value;
                    this.RaiseDataMemberChanged("_ETag");
                    this.On_ETagChanged();
                }
            }
        }
        
        [DataMember()]
        [Required()]
        public string Comments
        {
            get
            {
                return this._comments;
            }
            set
            {
                if ((this._comments != value))
                {
                    this.ValidateProperty("Comments", value);
                    this.OnCommentsChanging(value);
                    this.RaiseDataMemberChanging("Comments");
                    this._comments = value;
                    this.RaiseDataMemberChanged("Comments");
                    this.OnCommentsChanged();
                }
            }
        }
        
        [DataMember()]
        [Display(AutoGenerateField=false)]
        [Key()]
        [ReadOnly(true)]
        public string PartitionKey
        {
            get
            {
                return this._partitionKey;
            }
            set
            {
                if ((this._partitionKey != value))
                {
                    this.ValidateProperty("PartitionKey", value);
                    this.OnPartitionKeyChanging(value);
                    this.RaiseDataMemberChanging("PartitionKey");
                    this._partitionKey = value;
                    this.RaiseDataMemberChanged("PartitionKey");
                    this.OnPartitionKeyChanged();
                }
            }
        }
        
        [DataMember()]
        [Range(0, 100)]
        [Required()]
        public Nullable<int> Rating
        {
            get
            {
                return this._rating;
            }
            set
            {
                if ((this._rating != value))
                {
                    this.ValidateProperty("Rating", value);
                    this.OnRatingChanging(value);
                    this.RaiseDataMemberChanging("Rating");
                    this._rating = value;
                    this.RaiseDataMemberChanged("Rating");
                    this.OnRatingChanged();
                }
            }
        }
        
        [DataMember()]
        [Display(AutoGenerateField=false)]
        [Key()]
        [ReadOnly(true)]
        public string RowKey
        {
            get
            {
                return this._rowKey;
            }
            set
            {
                if ((this._rowKey != value))
                {
                    this.ValidateProperty("RowKey", value);
                    this.OnRowKeyChanging(value);
                    this.RaiseDataMemberChanging("RowKey");
                    this._rowKey = value;
                    this.RaiseDataMemberChanged("RowKey");
                    this.OnRowKeyChanged();
                }
            }
        }
        
        [DataMember()]
        [Display(AutoGenerateField=false)]
        [Required()]
        public string Target
        {
            get
            {
                return this._target;
            }
            set
            {
                if ((this._target != value))
                {
                    this.ValidateProperty("Target", value);
                    this.OnTargetChanging(value);
                    this.RaiseDataMemberChanging("Target");
                    this._target = value;
                    this.RaiseDataMemberChanged("Target");
                    this.OnTargetChanged();
                }
            }
        }
        
        [DataMember()]
        [Display(AutoGenerateField=false)]
        [ReadOnly(true)]
        [Timestamp()]
        public DateTime Timestamp
        {
            get
            {
                return this._timestamp;
            }
            set
            {
                if ((this._timestamp != value))
                {
                    this.ValidateProperty("Timestamp", value);
                    this.OnTimestampChanging(value);
                    this.RaiseDataMemberChanging("Timestamp");
                    this._timestamp = value;
                    this.RaiseDataMemberChanged("Timestamp");
                    this.OnTimestampChanged();
                }
            }
        }
        
        public override object GetIdentity()
        {
            return EntityKey.Create(this._partitionKey, this._rowKey);
        }
    }
}
namespace Hanray.Azurelight.Service
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Web.Ria.Data;
    using System.Windows.Ria.Data;
    using Hanray.Azurelight.Model;
    
    
    public sealed partial class SurveyContext : DomainContext
    {
        
        #region Extensibility Method Definitions

        /// <summary>
        /// This method is invoked from the constructor once initialization is complete and
        /// can be used for further object setup.
        /// </summary>
        partial void OnCreated();

        #endregion
        
        
        /// <summary>
        /// Default constructor.
        /// </summary>
        public SurveyContext() : 
                this(new HttpDomainClient(new Uri("DataService.axd/Hanray-Azurelight-Service-SurveyService/", System.UriKind.Relative)))
        {
        }
        
        /// <summary>
        /// Constructor used to specify a data service URI.
        /// </summary>
        /// <param name="serviceUri">
        /// The SurveyService data service URI.
        /// </param>
        public SurveyContext(Uri serviceUri) : 
                this(new HttpDomainClient(serviceUri))
        {
        }
        
        /// <summary>
        /// Constructor used to specify a DomainClient instance.
        /// </summary>
        /// <param name="domainClient">
        /// The DomainClient instance the DomainContext should use.
        /// </param>
        public SurveyContext(DomainClient domainClient) : 
                base(domainClient)
        {
            this.OnCreated();
        }
        
        public EntityList<Survey> Surveys
        {
            get
            {
                return base.Entities.GetEntityList<Survey>();
            }
        }
        
        /// <summary>
        /// Returns an EntityQuery for query operation 'GetSurveys'.
        /// </summary>
        public EntityQuery<Survey> GetSurveysQuery()
        {
            return base.CreateQuery<Survey>("GetSurveys", null, false, true);
        }
        
        protected override EntityContainer CreateEntityContainer()
        {
            return new SurveyContextEntityContainer();
        }
        
        internal sealed class SurveyContextEntityContainer : EntityContainer
        {
            
            public SurveyContextEntityContainer()
            {
                this.CreateEntityList<Survey>((EntityListOperations.Add | EntityListOperations.Edit));
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)


Written By
Technical Lead
United States United States
https://github.com/modesty

https://www.linkedin.com/in/modesty-zhang-9a43771

https://twitter.com/modestyqz

Comments and Discussions