Click here to Skip to main content
15,891,423 members
Articles / Programming Languages / C# 4.0

Introduction to ADO.NET Data Services/RIA Services

Rate me:
Please Sign up or sign in to vote.
4.93/5 (51 votes)
25 Feb 2010CPOL26 min read 180.7K   2.5K   166  
An introduction to ADO.NET Data Services / RIA Services.
//------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated from a template.
//
//    Manual changes to this file may cause unexpected behavior in your application.
//    Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Data.EntityClient;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Runtime.Serialization;

[assembly: EdmSchemaAttribute()]
#region EDM Relationship Metadata

[assembly: EdmRelationshipAttribute("DemoAppModel", "FK_Customers_Address", "Address", System.Data.Metadata.Edm.RelationshipMultiplicity.One, typeof(WCFDataServicesDemoApp.Web.Address), "Customers", System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(WCFDataServicesDemoApp.Web.Customer), true)]
[assembly: EdmRelationshipAttribute("DemoAppModel", "FK_Customers_Address1", "Address", System.Data.Metadata.Edm.RelationshipMultiplicity.ZeroOrOne, typeof(WCFDataServicesDemoApp.Web.Address), "Customers", System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(WCFDataServicesDemoApp.Web.Customer), true)]

#endregion

namespace WCFDataServicesDemoApp.Web
{
    #region Contexts
    
    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    public partial class DemoAppEntities : ObjectContext
    {
        #region Constructors
    
        /// <summary>
        /// Initializes a new DemoAppEntities object using the connection string found in the 'DemoAppEntities' section of the application configuration file.
        /// </summary>
        public DemoAppEntities() : base("name=DemoAppEntities", "DemoAppEntities")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }
    
        /// <summary>
        /// Initialize a new DemoAppEntities object.
        /// </summary>
        public DemoAppEntities(string connectionString) : base(connectionString, "DemoAppEntities")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }
    
        /// <summary>
        /// Initialize a new DemoAppEntities object.
        /// </summary>
        public DemoAppEntities(EntityConnection connection) : base(connection, "DemoAppEntities")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }
    
        #endregion
    
        #region Partial Methods
    
        partial void OnContextCreated();
    
        #endregion
    
        #region ObjectSet Properties
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        public ObjectSet<Address> Addresses
        {
            get
            {
                if ((_Addresses == null))
                {
                    _Addresses = base.CreateObjectSet<Address>("Addresses");
                }
                return _Addresses;
            }
        }
        private ObjectSet<Address> _Addresses;
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        public ObjectSet<Customer> Customers
        {
            get
            {
                if ((_Customers == null))
                {
                    _Customers = base.CreateObjectSet<Customer>("Customers");
                }
                return _Customers;
            }
        }
        private ObjectSet<Customer> _Customers;

        #endregion
        #region AddTo Methods
    
        /// <summary>
        /// Deprecated Method for adding a new object to the Addresses EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
        /// </summary>
        public void AddToAddresses(Address address)
        {
            base.AddObject("Addresses", address);
        }
    
        /// <summary>
        /// Deprecated Method for adding a new object to the Customers EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
        /// </summary>
        public void AddToCustomers(Customer customer)
        {
            base.AddObject("Customers", customer);
        }

        #endregion
    }
    

    #endregion
    
    #region Entities
    
    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmEntityTypeAttribute(NamespaceName="DemoAppModel", Name="Address")]
    [Serializable()]
    [DataContractAttribute(IsReference=true)]
    public partial class Address : EntityObject
    {
        #region Factory Method
    
        /// <summary>
        /// Create a new Address object.
        /// </summary>
        /// <param name="addressId">Initial value of the AddressId property.</param>
        /// <param name="city">Initial value of the City property.</param>
        /// <param name="line1">Initial value of the Line1 property.</param>
        /// <param name="postCode">Initial value of the PostCode property.</param>
        public static Address CreateAddress(global::System.Int32 addressId, global::System.String city, global::System.String line1, global::System.String postCode)
        {
            Address address = new Address();
            address.AddressId = addressId;
            address.City = city;
            address.Line1 = line1;
            address.PostCode = postCode;
            return address;
        }

        #endregion
        #region Primitive Properties
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Int32 AddressId
        {
            get
            {
                return _AddressId;
            }
            set
            {
                if (_AddressId != value)
                {
                    OnAddressIdChanging(value);
                    ReportPropertyChanging("AddressId");
                    _AddressId = StructuralObject.SetValidValue(value);
                    ReportPropertyChanged("AddressId");
                    OnAddressIdChanged();
                }
            }
        }
        private global::System.Int32 _AddressId;
        partial void OnAddressIdChanging(global::System.Int32 value);
        partial void OnAddressIdChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String City
        {
            get
            {
                return _City;
            }
            set
            {
                OnCityChanging(value);
                ReportPropertyChanging("City");
                _City = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("City");
                OnCityChanged();
            }
        }
        private global::System.String _City;
        partial void OnCityChanging(global::System.String value);
        partial void OnCityChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String Line1
        {
            get
            {
                return _Line1;
            }
            set
            {
                OnLine1Changing(value);
                ReportPropertyChanging("Line1");
                _Line1 = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("Line1");
                OnLine1Changed();
            }
        }
        private global::System.String _Line1;
        partial void OnLine1Changing(global::System.String value);
        partial void OnLine1Changed();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public global::System.String Line2
        {
            get
            {
                return _Line2;
            }
            set
            {
                OnLine2Changing(value);
                ReportPropertyChanging("Line2");
                _Line2 = StructuralObject.SetValidValue(value, true);
                ReportPropertyChanged("Line2");
                OnLine2Changed();
            }
        }
        private global::System.String _Line2;
        partial void OnLine2Changing(global::System.String value);
        partial void OnLine2Changed();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String PostCode
        {
            get
            {
                return _PostCode;
            }
            set
            {
                OnPostCodeChanging(value);
                ReportPropertyChanging("PostCode");
                _PostCode = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("PostCode");
                OnPostCodeChanged();
            }
        }
        private global::System.String _PostCode;
        partial void OnPostCodeChanging(global::System.String value);
        partial void OnPostCodeChanged();

        #endregion
    
        #region Navigation Properties
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [XmlIgnoreAttribute()]
        [SoapIgnoreAttribute()]
        [DataMemberAttribute()]
        [EdmRelationshipNavigationPropertyAttribute("DemoAppModel", "FK_Customers_Address", "Customers")]
        public EntityCollection<Customer> Customers
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<Customer>("DemoAppModel.FK_Customers_Address", "Customers");
            }
            set
            {
                if ((value != null))
                {
                    ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection<Customer>("DemoAppModel.FK_Customers_Address", "Customers", value);
                }
            }
        }
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [XmlIgnoreAttribute()]
        [SoapIgnoreAttribute()]
        [DataMemberAttribute()]
        [EdmRelationshipNavigationPropertyAttribute("DemoAppModel", "FK_Customers_Address1", "Customers")]
        public EntityCollection<Customer> Customers1
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<Customer>("DemoAppModel.FK_Customers_Address1", "Customers");
            }
            set
            {
                if ((value != null))
                {
                    ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection<Customer>("DemoAppModel.FK_Customers_Address1", "Customers", value);
                }
            }
        }

        #endregion
    }
    
    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmEntityTypeAttribute(NamespaceName="DemoAppModel", Name="Customer")]
    [Serializable()]
    [DataContractAttribute(IsReference=true)]
    public partial class Customer : EntityObject
    {
        #region Factory Method
    
        /// <summary>
        /// Create a new Customer object.
        /// </summary>
        /// <param name="customerId">Initial value of the CustomerId property.</param>
        /// <param name="name">Initial value of the Name property.</param>
        /// <param name="phone">Initial value of the Phone property.</param>
        /// <param name="email">Initial value of the Email property.</param>
        /// <param name="shippingAddress">Initial value of the ShippingAddress property.</param>
        public static Customer CreateCustomer(global::System.Int32 customerId, global::System.String name, global::System.String phone, global::System.String email, global::System.Int32 shippingAddress)
        {
            Customer customer = new Customer();
            customer.CustomerId = customerId;
            customer.Name = name;
            customer.Phone = phone;
            customer.Email = email;
            customer.ShippingAddress = shippingAddress;
            return customer;
        }

        #endregion
        #region Primitive Properties
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Int32 CustomerId
        {
            get
            {
                return _CustomerId;
            }
            set
            {
                if (_CustomerId != value)
                {
                    OnCustomerIdChanging(value);
                    ReportPropertyChanging("CustomerId");
                    _CustomerId = StructuralObject.SetValidValue(value);
                    ReportPropertyChanged("CustomerId");
                    OnCustomerIdChanged();
                }
            }
        }
        private global::System.Int32 _CustomerId;
        partial void OnCustomerIdChanging(global::System.Int32 value);
        partial void OnCustomerIdChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String Name
        {
            get
            {
                return _Name;
            }
            set
            {
                OnNameChanging(value);
                ReportPropertyChanging("Name");
                _Name = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("Name");
                OnNameChanged();
            }
        }
        private global::System.String _Name;
        partial void OnNameChanging(global::System.String value);
        partial void OnNameChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String Phone
        {
            get
            {
                return _Phone;
            }
            set
            {
                OnPhoneChanging(value);
                ReportPropertyChanging("Phone");
                _Phone = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("Phone");
                OnPhoneChanged();
            }
        }
        private global::System.String _Phone;
        partial void OnPhoneChanging(global::System.String value);
        partial void OnPhoneChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String Email
        {
            get
            {
                return _Email;
            }
            set
            {
                OnEmailChanging(value);
                ReportPropertyChanging("Email");
                _Email = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("Email");
                OnEmailChanged();
            }
        }
        private global::System.String _Email;
        partial void OnEmailChanging(global::System.String value);
        partial void OnEmailChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Int32 ShippingAddress
        {
            get
            {
                return _ShippingAddress;
            }
            set
            {
                OnShippingAddressChanging(value);
                ReportPropertyChanging("ShippingAddress");
                _ShippingAddress = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("ShippingAddress");
                OnShippingAddressChanged();
            }
        }
        private global::System.Int32 _ShippingAddress;
        partial void OnShippingAddressChanging(global::System.Int32 value);
        partial void OnShippingAddressChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public Nullable<global::System.Int32> AlternativeShippingAddress
        {
            get
            {
                return _AlternativeShippingAddress;
            }
            set
            {
                OnAlternativeShippingAddressChanging(value);
                ReportPropertyChanging("AlternativeShippingAddress");
                _AlternativeShippingAddress = StructuralObject.SetValidValue(value);
                ReportPropertyChanged("AlternativeShippingAddress");
                OnAlternativeShippingAddressChanged();
            }
        }
        private Nullable<global::System.Int32> _AlternativeShippingAddress;
        partial void OnAlternativeShippingAddressChanging(Nullable<global::System.Int32> value);
        partial void OnAlternativeShippingAddressChanged();

        #endregion
    
        #region Navigation Properties
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [XmlIgnoreAttribute()]
        [SoapIgnoreAttribute()]
        [DataMemberAttribute()]
        [EdmRelationshipNavigationPropertyAttribute("DemoAppModel", "FK_Customers_Address", "Address")]
        public Address Address
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Address>("DemoAppModel.FK_Customers_Address", "Address").Value;
            }
            set
            {
                ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Address>("DemoAppModel.FK_Customers_Address", "Address").Value = value;
            }
        }
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [BrowsableAttribute(false)]
        [DataMemberAttribute()]
        public EntityReference<Address> AddressReference
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Address>("DemoAppModel.FK_Customers_Address", "Address");
            }
            set
            {
                if ((value != null))
                {
                    ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<Address>("DemoAppModel.FK_Customers_Address", "Address", value);
                }
            }
        }
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [XmlIgnoreAttribute()]
        [SoapIgnoreAttribute()]
        [DataMemberAttribute()]
        [EdmRelationshipNavigationPropertyAttribute("DemoAppModel", "FK_Customers_Address1", "Address")]
        public Address Address1
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Address>("DemoAppModel.FK_Customers_Address1", "Address").Value;
            }
            set
            {
                ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Address>("DemoAppModel.FK_Customers_Address1", "Address").Value = value;
            }
        }
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [BrowsableAttribute(false)]
        [DataMemberAttribute()]
        public EntityReference<Address> Address1Reference
        {
            get
            {
                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Address>("DemoAppModel.FK_Customers_Address1", "Address");
            }
            set
            {
                if ((value != null))
                {
                    ((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<Address>("DemoAppModel.FK_Customers_Address1", "Address", value);
                }
            }
        }

        #endregion
    }

    #endregion
    
}

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 Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United Kingdom United Kingdom
I currently hold the following qualifications (amongst others, I also studied Music Technology and Electronics, for my sins)

- MSc (Passed with distinctions), in Information Technology for E-Commerce
- BSc Hons (1st class) in Computer Science & Artificial Intelligence

Both of these at Sussex University UK.

Award(s)

I am lucky enough to have won a few awards for Zany Crazy code articles over the years

  • Microsoft C# MVP 2016
  • Codeproject MVP 2016
  • Microsoft C# MVP 2015
  • Codeproject MVP 2015
  • Microsoft C# MVP 2014
  • Codeproject MVP 2014
  • Microsoft C# MVP 2013
  • Codeproject MVP 2013
  • Microsoft C# MVP 2012
  • Codeproject MVP 2012
  • Microsoft C# MVP 2011
  • Codeproject MVP 2011
  • Microsoft C# MVP 2010
  • Codeproject MVP 2010
  • Microsoft C# MVP 2009
  • Codeproject MVP 2009
  • Microsoft C# MVP 2008
  • Codeproject MVP 2008
  • And numerous codeproject awards which you can see over at my blog

Comments and Discussions