//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.4927
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace MasterDetailsWithRIAServices
{
    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;
    using System.Windows.Ria.Services;
    
    
    /// <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 WebContext : WebContextBase
    {
        
        #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 WebContext class.
        /// </summary>
        public WebContext()
        {
            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 WebContext Current
        {
            get
            {
                return ((WebContext)(WebContextBase.Current));
            }
        }
    }
}
namespace MasterDetailsWithRIAServices.Web.Models
{
    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;
    using System.Windows.Ria.Services;
    using System.Xml.Serialization;
    
    
    [DataContract(Namespace="http://schemas.datacontract.org/2004/07/MasterDetailsWithRIAServices.Web.Models")]
    public sealed partial class Album : Entity
    {
        
        private int _albumId;
        
        private EntityRef<Artist> _artist;
        
        private int _artistId;
        
        private string _title;
        
        #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 OnAlbumIdChanging(int value);
        partial void OnAlbumIdChanged();
        partial void OnArtistIdChanging(int value);
        partial void OnArtistIdChanged();
        partial void OnTitleChanging(string value);
        partial void OnTitleChanged();

        #endregion
        
        
        /// <summary>
        /// Default constructor.
        /// </summary>
        public Album()
        {
            this.OnCreated();
        }
        
        [DataMember()]
        [Key()]
        public int AlbumId
        {
            get
            {
                return this._albumId;
            }
            set
            {
                if ((this._albumId != value))
                {
                    this.ValidateProperty("AlbumId", value);
                    this.OnAlbumIdChanging(value);
                    this.RaiseDataMemberChanging("AlbumId");
                    this._albumId = value;
                    this.RaiseDataMemberChanged("AlbumId");
                    this.OnAlbumIdChanged();
                }
            }
        }
        
        [Association("Artist_Album", "ArtistId", "ArtistId", IsForeignKey=true)]
        [XmlIgnore()]
        public Artist Artist
        {
            get
            {
                if ((this._artist == null))
                {
                    this._artist = new EntityRef<Artist>(this, "Artist", this.FilterArtist);
                }
                return this._artist.Entity;
            }
            set
            {
                Artist previous = this.Artist;
                if ((previous != value))
                {
                    this.ValidateProperty("Artist", value);
                    if ((previous != null))
                    {
                        this._artist.Entity = null;
                        previous.Album.Remove(this);
                    }
                    if ((value != null))
                    {
                        this.ArtistId = value.ArtistId;
                    }
                    else
                    {
                        this.ArtistId = default(int);
                    }
                    this._artist.Entity = value;
                    if ((value != null))
                    {
                        value.Album.Add(this);
                    }
                    this.RaisePropertyChanged("Artist");
                }
            }
        }
        
        [DataMember()]
        public int ArtistId
        {
            get
            {
                return this._artistId;
            }
            set
            {
                if ((this._artistId != value))
                {
                    this.ValidateProperty("ArtistId", value);
                    this.OnArtistIdChanging(value);
                    this.RaiseDataMemberChanging("ArtistId");
                    this._artistId = value;
                    this.RaiseDataMemberChanged("ArtistId");
                    this.OnArtistIdChanged();
                }
            }
        }
        
        [DataMember()]
        [StringLength(160)]
        public string Title
        {
            get
            {
                return this._title;
            }
            set
            {
                if ((this._title != value))
                {
                    this.ValidateProperty("Title", value);
                    this.OnTitleChanging(value);
                    this.RaiseDataMemberChanging("Title");
                    this._title = value;
                    this.RaiseDataMemberChanged("Title");
                    this.OnTitleChanged();
                }
            }
        }
        
        private bool FilterArtist(Artist entity)
        {
            return (entity.ArtistId == this.ArtistId);
        }
        
        public override object GetIdentity()
        {
            return this._albumId;
        }
    }
    
    [DataContract(Namespace="http://schemas.datacontract.org/2004/07/MasterDetailsWithRIAServices.Web.Models")]
    public sealed partial class Artist : Entity
    {
        
        private EntityCollection<Album> _album;
        
        private int _artistId;
        
        private string _name;
        
        #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 OnArtistIdChanging(int value);
        partial void OnArtistIdChanged();
        partial void OnNameChanging(string value);
        partial void OnNameChanged();

        #endregion
        
        
        /// <summary>
        /// Default constructor.
        /// </summary>
        public Artist()
        {
            this.OnCreated();
        }
        
        [Association("Artist_Album", "ArtistId", "ArtistId")]
        [XmlIgnore()]
        public EntityCollection<Album> Album
        {
            get
            {
                if ((this._album == null))
                {
                    this._album = new EntityCollection<Album>(this, "Album", this.FilterAlbum, this.AttachAlbum, this.DetachAlbum);
                }
                return this._album;
            }
        }
        
        [DataMember()]
        [Key()]
        public int ArtistId
        {
            get
            {
                return this._artistId;
            }
            set
            {
                if ((this._artistId != value))
                {
                    this.ValidateProperty("ArtistId", value);
                    this.OnArtistIdChanging(value);
                    this.RaiseDataMemberChanging("ArtistId");
                    this._artistId = value;
                    this.RaiseDataMemberChanged("ArtistId");
                    this.OnArtistIdChanged();
                }
            }
        }
        
        [DataMember()]
        [StringLength(120)]
        public string Name
        {
            get
            {
                return this._name;
            }
            set
            {
                if ((this._name != value))
                {
                    this.ValidateProperty("Name", value);
                    this.OnNameChanging(value);
                    this.RaiseDataMemberChanging("Name");
                    this._name = value;
                    this.RaiseDataMemberChanged("Name");
                    this.OnNameChanged();
                }
            }
        }
        
        private void AttachAlbum(Album entity)
        {
            entity.Artist = this;
        }
        
        private void DetachAlbum(Album entity)
        {
            entity.Artist = null;
        }
        
        private bool FilterAlbum(Album entity)
        {
            return (entity.ArtistId == this.ArtistId);
        }
        
        public override object GetIdentity()
        {
            return this._artistId;
        }
    }
}
namespace MasterDetailsWithRIAServices.Web.Services
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.ServiceModel;
    using System.Web.Ria.Data;
    using System.Windows.Ria;
    using System.Windows.Ria.Services;
    using MasterDetailsWithRIAServices.Web.Models;
    
    
    public sealed partial class ChinookContext : 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 ChinookContext() : 
                this(new WebDomainClient<IChinookServiceContract>(new Uri("MasterDetailsWithRIAServices-Web-Services-ChinookService.svc", UriKind.Relative)))
        {
        }
        
        /// <summary>
        /// Constructor used to specify a data service URI.
        /// </summary>
        /// <param name="serviceUri">
        /// The ChinookService data service URI.
        /// </param>
        public ChinookContext(Uri serviceUri) : 
                this(new WebDomainClient<IChinookServiceContract>(serviceUri))
        {
        }
        
        /// <summary>
        /// Constructor used to specify a DomainClient instance.
        /// </summary>
        /// <param name="domainClient">
        /// The DomainClient instance the DomainContext should use.
        /// </param>
        public ChinookContext(DomainClient domainClient) : 
                base(domainClient)
        {
            this.OnCreated();
        }
        
        public EntitySet<Album> Albums
        {
            get
            {
                return base.EntityContainer.GetEntitySet<Album>();
            }
        }
        
        public EntitySet<Artist> Artists
        {
            get
            {
                return base.EntityContainer.GetEntitySet<Artist>();
            }
        }
        
        /// <summary>
        /// Returns an EntityQuery for query operation 'GetAlbums'.
        /// </summary>
        public EntityQuery<Album> GetAlbumsQuery()
        {
            this.ValidateMethod("GetAlbumsQuery", null);
            return base.CreateQuery<Album>("GetAlbums", null, false, true);
        }
        
        /// <summary>
        /// Returns an EntityQuery for query operation 'GetAlbumsForArtistId'.
        /// </summary>
        public EntityQuery<Album> GetAlbumsForArtistIdQuery(int artistId)
        {
            Dictionary<string, object> parameters = new Dictionary<string, object>();
            parameters.Add("artistId", artistId);
            this.ValidateMethod("GetAlbumsForArtistIdQuery", parameters);
            return base.CreateQuery<Album>("GetAlbumsForArtistId", parameters, false, true);
        }
        
        /// <summary>
        /// Returns an EntityQuery for query operation 'GetArtists'.
        /// </summary>
        public EntityQuery<Artist> GetArtistsQuery()
        {
            this.ValidateMethod("GetArtistsQuery", null);
            return base.CreateQuery<Artist>("GetArtists", null, false, true);
        }
        
        protected override EntityContainer CreateEntityContainer()
        {
            return new ChinookContextEntityContainer();
        }
        
        [ServiceContract()]
        public interface IChinookServiceContract
        {
            
            [FaultContract(typeof(DomainServiceFault), Action="http://tempuri.org/ChinookService/GetAlbumsDomainServiceFault", Name="DomainServiceFault", Namespace="DomainServices")]
            [OperationContract(AsyncPattern=true, Action="http://tempuri.org/ChinookService/GetAlbums", ReplyAction="http://tempuri.org/ChinookService/GetAlbumsResponse")]
            IAsyncResult BeginGetAlbums(AsyncCallback callback, object asyncState);
            
            QueryResult<Album> EndGetAlbums(IAsyncResult result);
            
            [FaultContract(typeof(DomainServiceFault), Action="http://tempuri.org/ChinookService/GetArtistsDomainServiceFault", Name="DomainServiceFault", Namespace="DomainServices")]
            [OperationContract(AsyncPattern=true, Action="http://tempuri.org/ChinookService/GetArtists", ReplyAction="http://tempuri.org/ChinookService/GetArtistsResponse")]
            IAsyncResult BeginGetArtists(AsyncCallback callback, object asyncState);
            
            QueryResult<Artist> EndGetArtists(IAsyncResult result);
            
            [FaultContract(typeof(DomainServiceFault), Action="http://tempuri.org/ChinookService/GetAlbumsForArtistIdDomainServiceFault", Name="DomainServiceFault", Namespace="DomainServices")]
            [OperationContract(AsyncPattern=true, Action="http://tempuri.org/ChinookService/GetAlbumsForArtistId", ReplyAction="http://tempuri.org/ChinookService/GetAlbumsForArtistIdResponse")]
            IAsyncResult BeginGetAlbumsForArtistId(int artistId, AsyncCallback callback, object asyncState);
            
            QueryResult<Album> EndGetAlbumsForArtistId(IAsyncResult result);
            
            [FaultContract(typeof(DomainServiceFault), Action="http://tempuri.org/ChinookService/SubmitChangesDomainServiceFault", Name="DomainServiceFault", Namespace="DomainServices")]
            [OperationContract(AsyncPattern=true, Action="http://tempuri.org/ChinookService/SubmitChanges", ReplyAction="http://tempuri.org/ChinookService/SubmitChangesResponse")]
            IAsyncResult BeginSubmitChanges(IEnumerable<ChangeSetEntry> changeSet, AsyncCallback callback, object asyncState);
            
            IEnumerable<ChangeSetEntry> EndSubmitChanges(IAsyncResult result);
        }
        
        internal sealed class ChinookContextEntityContainer : EntityContainer
        {
            
            public ChinookContextEntityContainer()
            {
                this.CreateEntitySet<Album>(EntitySetOperations.All);
                this.CreateEntitySet<Artist>(EntitySetOperations.All);
            }
        }
    }
}
