we touched briefly on entity framework and the benefits it provides. In this post we will walk through the process of creating an entity data model object in our project and then in future post use it to create a functional project. If you have worked with
, you will find the process very similar when it comes to generating the EDM files, but in my view, entity framework is much more powerful and simpler to use than typed datasets.
Lets create a test project and then create an entity data model file. We will use a sample database that I have created in my test environment.
We will create a simple Winform application and add a combobox to display all the customers in the database.
1.
//------------------------------------------------------------------------------
// <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.ComponentModel;
using System.Data.EntityClient;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Linq;
using System.Runtime.Serialization;
using System.Xml.Serialization;
[assembly: EdmSchemaAttribute()]
#region EDM Relationship Metadata
[assembly: EdmRelationshipAttribute("OrdersModel", "FK_CustomerAddress_Customers", "Customers", System.Data.Metadata.Edm.RelationshipMultiplicity.One, typeof(EntiryFramework.Customer), "CustomerAddress", System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(EntiryFramework.CustomerAddress), true)]
[assembly: EdmRelationshipAttribute("OrdersModel", "FK_Orders_Customers", "Customers", System.Data.Metadata.Edm.RelationshipMultiplicity.One, typeof(EntiryFramework.Customer), "Orders", System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(EntiryFramework.Order), true)]
[assembly: EdmRelationshipAttribute("OrdersModel", "FK_OrderDetails_Items", "Items", System.Data.Metadata.Edm.RelationshipMultiplicity.One, typeof(EntiryFramework.Item), "OrderDetails", System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(EntiryFramework.OrderDetail), true)]
[assembly: EdmRelationshipAttribute("OrdersModel", "FK_OrderDetails_Orders", "Orders", System.Data.Metadata.Edm.RelationshipMultiplicity.One, typeof(EntiryFramework.Order), "OrderDetails", System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(EntiryFramework.OrderDetail), true)]
[assembly: EdmRelationshipAttribute("OrdersModel", "FK_Orders_SalesPerson", "SalesPerson", System.Data.Metadata.Edm.RelationshipMultiplicity.ZeroOrOne, typeof(EntiryFramework.SalesPerson), "Orders", System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(EntiryFramework.Order), true)]
#endregion
namespace EntiryFramework
{
#region Contexts
/// <summary>
/// No Metadata Documentation available.
/// </summary>
public partial class OrdersEntities : ObjectContext
{
#region Constructors
/// <summary>
/// Initializes a new OrdersEntities object using the connection string found in the 'OrdersEntities' section of the application configuration file.
/// </summary>
public OrdersEntities() : base("name=OrdersEntities", "OrdersEntities")
{
this.ContextOptions.LazyLoadingEnabled = true;
OnContextCreated();
}
/// <summary>
/// Initialize a new OrdersEntities object.
/// </summary>
public OrdersEntities(string connectionString) : base(connectionString, "OrdersEntities")
{
this.ContextOptions.LazyLoadingEnabled = true;
OnContextCreated();
}
/// <summary>
/// Initialize a new OrdersEntities object.
/// </summary>
public OrdersEntities(EntityConnection connection) : base(connection, "OrdersEntities")
{
this.ContextOptions.LazyLoadingEnabled = true;
OnContextCreated();
}
#endregion
#region Partial Methods
partial void OnContextCreated();
#endregion
#region ObjectSet Properties
/// <summary>
/// No Metadata Documentation available.
/// </summary>
public ObjectSet<CustomerAddress> CustomerAddresses
{
get
{
if ((_CustomerAddresses == null))
{
_CustomerAddresses = base.CreateObjectSet<CustomerAddress>("CustomerAddresses");
}
return _CustomerAddresses;
}
}
private ObjectSet<CustomerAddress> _CustomerAddresses;
/// <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;
/// <summary>
/// No Metadata Documentation available.
/// </summary>
public ObjectSet<Item> Items
{
get
{
if ((_Items == null))
{
_Items = base.CreateObjectSet<Item>("Items");
}
return _Items;
}
}
private ObjectSet<Item> _Items;
/// <summary>
/// No Metadata Documentation available.
/// </summary>
public ObjectSet<OrderDetail> OrderDetails
{
get
{
if ((_OrderDetails == null))
{
_OrderDetails = base.CreateObjectSet<OrderDetail>("OrderDetails");
}
return _OrderDetails;
}
}
private ObjectSet<OrderDetail> _OrderDetails;
/// <summary>
/// No Metadata Documentation available.
/// </summary>
public ObjectSet<Order> Orders
{
get
{
if ((_Orders == null))
{
_Orders = base.CreateObjectSet<Order>("Orders");
}
return _Orders;
}
}
private ObjectSet<Order> _Orders;
/// <summary>
/// No Metadata Documentation available.
/// </summary>
public ObjectSet<SalesPerson> SalesPersons
{
get
{
if ((_SalesPersons == null))
{
_SalesPersons = base.CreateObjectSet<SalesPerson>("SalesPersons");
}
return _SalesPersons;
}
}
private ObjectSet<SalesPerson> _SalesPersons;
/// <summary>
/// No Metadata Documentation available.
/// </summary>
public ObjectSet<sysdiagram> sysdiagrams
{
get
{
if ((_sysdiagrams == null))
{
_sysdiagrams = base.CreateObjectSet<sysdiagram>("sysdiagrams");
}
return _sysdiagrams;
}
}
private ObjectSet<sysdiagram> _sysdiagrams;
#endregion
#region AddTo Methods
/// <summary>
/// Deprecated Method for adding a new object to the CustomerAddresses EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead.
/// </summary>
public void AddToCustomerAddresses(CustomerAddress customerAddress)
{
base.AddObject("CustomerAddresses", customerAddress);
}
/// <summary>
/// Deprecated Method for adding a new object to the Customers EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead.
/// </summary>
public void AddToCustomers(Customer customer)
{
base.AddObject("Customers", customer);
}
/// <summary>
/// Deprecated Method for adding a new object to the Items EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead.
/// </summary>
public void AddToItems(Item item)
{
base.AddObject("Items", item);
}
/// <summary>
/// Deprecated Method for adding a new object to the OrderDetails EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead.
/// </summary>
public void AddToOrderDetails(OrderDetail orderDetail)
{
base.AddObject("OrderDetails", orderDetail);
}
/// <summary>
/// Deprecated Method for adding a new object to the Orders EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead.
/// </summary>
public void AddToOrders(Order order)
{
base.AddObject("Orders", order);
}
/// <summary>
/// Deprecated Method for adding a new object to the SalesPersons EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead.
/// </summary>
public void AddToSalesPersons(SalesPerson salesPerson)
{
base.AddObject("SalesPersons", salesPerson);
}
/// <summary>
/// Deprecated Method for adding a new object to the sysdiagrams EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead.
/// </summary>
public void AddTosysdiagrams(sysdiagram sysdiagram)
{
base.AddObject("sysdiagrams", sysdiagram);
}
#endregion
}
#endregion
#region Entities
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmEntityTypeAttribute(NamespaceName="OrdersModel", 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>
public static Customer CreateCustomer(global::System.Int32 customerID)
{
Customer customer = new Customer();
customer.CustomerID = customerID;
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=true)]
[DataMemberAttribute()]
public global::System.String FirstName
{
get
{
return _FirstName;
}
set
{
OnFirstNameChanging(value);
ReportPropertyChanging("FirstName");
_FirstName = StructuralObject.SetValidValue(value, true);
ReportPropertyChanged("FirstName");
OnFirstNameChanged();
}
}
private global::System.String _FirstName;
partial void OnFirstNameChanging(global::System.String value);
partial void OnFirstNameChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.String LastName
{
get
{
return _LastName;
}
set
{
OnLastNameChanging(value);
ReportPropertyChanging("LastName");
_LastName = StructuralObject.SetValidValue(value, true);
ReportPropertyChanged("LastName");
OnLastNameChanged();
}
}
private global::System.String _LastName;
partial void OnLastNameChanging(global::System.String value);
partial void OnLastNameChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.String EmailAddress
{
get
{
return _EmailAddress;
}
set
{
OnEmailAddressChanging(value);
ReportPropertyChanging("EmailAddress");
_EmailAddress = StructuralObject.SetValidValue(value, true);
ReportPropertyChanged("EmailAddress");
OnEmailAddressChanged();
}
}
private global::System.String _EmailAddress;
partial void OnEmailAddressChanging(global::System.String value);
partial void OnEmailAddressChanged();
#endregion
#region Navigation Properties
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[XmlIgnoreAttribute()]
[SoapIgnoreAttribute()]
[DataMemberAttribute()]
[EdmRelationshipNavigationPropertyAttribute("OrdersModel", "FK_CustomerAddress_Customers", "CustomerAddress")]
public EntityCollection<CustomerAddress> CustomerAddresses
{
get
{
return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<CustomerAddress>("OrdersModel.FK_CustomerAddress_Customers", "CustomerAddress");
}
set
{
if ((value != null))
{
((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection<CustomerAddress>("OrdersModel.FK_CustomerAddress_Customers", "CustomerAddress", value);
}
}
}
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[XmlIgnoreAttribute()]
[SoapIgnoreAttribute()]
[DataMemberAttribute()]
[EdmRelationshipNavigationPropertyAttribute("OrdersModel", "FK_Orders_Customers", "Orders")]
public EntityCollection<Order> Orders
{
get
{
return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<Order>("OrdersModel.FK_Orders_Customers", "Orders");
}
set
{
if ((value != null))
{
((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection<Order>("OrdersModel.FK_Orders_Customers", "Orders", value);
}
}
}
#endregion
}
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmEntityTypeAttribute(NamespaceName="OrdersModel", Name="CustomerAddress")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class CustomerAddress : EntityObject
{
#region Factory Method
/// <summary>
/// Create a new CustomerAddress object.
/// </summary>
/// <param name="addressID">Initial value of the AddressID property.</param>
/// <param name="customerID">Initial value of the CustomerID property.</param>
public static CustomerAddress CreateCustomerAddress(global::System.Int32 addressID, global::System.Int32 customerID)
{
CustomerAddress customerAddress = new CustomerAddress();
customerAddress.AddressID = addressID;
customerAddress.CustomerID = customerID;
return customerAddress;
}
#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=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=true)]
[DataMemberAttribute()]
public global::System.String Address1
{
get
{
return _Address1;
}
set
{
OnAddress1Changing(value);
ReportPropertyChanging("Address1");
_Address1 = StructuralObject.SetValidValue(value, true);
ReportPropertyChanged("Address1");
OnAddress1Changed();
}
}
private global::System.String _Address1;
partial void OnAddress1Changing(global::System.String value);
partial void OnAddress1Changed();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.String Address2
{
get
{
return _Address2;
}
set
{
OnAddress2Changing(value);
ReportPropertyChanging("Address2");
_Address2 = StructuralObject.SetValidValue(value, true);
ReportPropertyChanged("Address2");
OnAddress2Changed();
}
}
private global::System.String _Address2;
partial void OnAddress2Changing(global::System.String value);
partial void OnAddress2Changed();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.String City
{
get
{
return _City;
}
set
{
OnCityChanging(value);
ReportPropertyChanging("City");
_City = StructuralObject.SetValidValue(value, true);
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=true)]
[DataMemberAttribute()]
public global::System.String State
{
get
{
return _State;
}
set
{
OnStateChanging(value);
ReportPropertyChanging("State");
_State = StructuralObject.SetValidValue(value, true);
ReportPropertyChanged("State");
OnStateChanged();
}
}
private global::System.String _State;
partial void OnStateChanging(global::System.String value);
partial void OnStateChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.String ZipCode
{
get
{
return _ZipCode;
}
set
{
OnZipCodeChanging(value);
ReportPropertyChanging("ZipCode");
_ZipCode = StructuralObject.SetValidValue(value, true);
ReportPropertyChanged("ZipCode");
OnZipCodeChanged();
}
}
private global::System.String _ZipCode;
partial void OnZipCodeChanging(global::System.String value);
partial void OnZipCodeChanged();
#endregion
#region Navigation Properties
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[XmlIgnoreAttribute()]
[SoapIgnoreAttribute()]
[DataMemberAttribute()]
[EdmRelationshipNavigationPropertyAttribute("OrdersModel", "FK_CustomerAddress_Customers", "Customers")]
public Customer Customer
{
get
{
return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Customer>("OrdersModel.FK_CustomerAddress_Customers", "Customers").Value;
}
set
{
((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Customer>("OrdersModel.FK_CustomerAddress_Customers", "Customers").Value = value;
}
}
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[BrowsableAttribute(false)]
[DataMemberAttribute()]
public EntityReference<Customer> CustomerReference
{
get
{
return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Customer>("OrdersModel.FK_CustomerAddress_Customers", "Customers");
}
set
{
if ((value != null))
{
((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<Customer>("OrdersModel.FK_CustomerAddress_Customers", "Customers", value);
}
}
}
#endregion
}
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmEntityTypeAttribute(NamespaceName="OrdersModel", Name="Item")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class Item : EntityObject
{
#region Factory Method
/// <summary>
/// Create a new Item object.
/// </summary>
/// <param name="itemID">Initial value of the ItemID property.</param>
public static Item CreateItem(global::System.Int32 itemID)
{
Item item = new Item();
item.ItemID = itemID;
return item;
}
#endregion
#region Primitive Properties
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 ItemID
{
get
{
return _ItemID;
}
set
{
if (_ItemID != value)
{
OnItemIDChanging(value);
ReportPropertyChanging("ItemID");
_ItemID = StructuralObject.SetValidValue(value);
ReportPropertyChanged("ItemID");
OnItemIDChanged();
}
}
}
private global::System.Int32 _ItemID;
partial void OnItemIDChanging(global::System.Int32 value);
partial void OnItemIDChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.String Description
{
get
{
return _Description;
}
set
{
OnDescriptionChanging(value);
ReportPropertyChanging("Description");
_Description = StructuralObject.SetValidValue(value, true);
ReportPropertyChanged("Description");
OnDescriptionChanged();
}
}
private global::System.String _Description;
partial void OnDescriptionChanging(global::System.String value);
partial void OnDescriptionChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public Nullable<global::System.Int32> QuantityOnHand
{
get
{
return _QuantityOnHand;
}
set
{
OnQuantityOnHandChanging(value);
ReportPropertyChanging("QuantityOnHand");
_QuantityOnHand = StructuralObject.SetValidValue(value);
ReportPropertyChanged("QuantityOnHand");
OnQuantityOnHandChanged();
}
}
private Nullable<global::System.Int32> _QuantityOnHand;
partial void OnQuantityOnHandChanging(Nullable<global::System.Int32> value);
partial void OnQuantityOnHandChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public Nullable<global::System.Decimal> SalesPrice
{
get
{
return _SalesPrice;
}
set
{
OnSalesPriceChanging(value);
ReportPropertyChanging("SalesPrice");
_SalesPrice = StructuralObject.SetValidValue(value);
ReportPropertyChanged("SalesPrice");
OnSalesPriceChanged();
}
}
private Nullable<global::System.Decimal> _SalesPrice;
partial void OnSalesPriceChanging(Nullable<global::System.Decimal> value);
partial void OnSalesPriceChanged();
#endregion
#region Navigation Properties
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[XmlIgnoreAttribute()]
[SoapIgnoreAttribute()]
[DataMemberAttribute()]
[EdmRelationshipNavigationPropertyAttribute("OrdersModel", "FK_OrderDetails_Items", "OrderDetails")]
public EntityCollection<OrderDetail> OrderDetails
{
get
{
return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<OrderDetail>("OrdersModel.FK_OrderDetails_Items", "OrderDetails");
}
set
{
if ((value != null))
{
((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection<OrderDetail>("OrdersModel.FK_OrderDetails_Items", "OrderDetails", value);
}
}
}
#endregion
}
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmEntityTypeAttribute(NamespaceName="OrdersModel", Name="Order")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class Order : EntityObject
{
#region Factory Method
/// <summary>
/// Create a new Order object.
/// </summary>
/// <param name="orderID">Initial value of the OrderID property.</param>
/// <param name="customerID">Initial value of the CustomerID property.</param>
public static Order CreateOrder(global::System.Int32 orderID, global::System.Int32 customerID)
{
Order order = new Order();
order.OrderID = orderID;
order.CustomerID = customerID;
return order;
}
#endregion
#region Primitive Properties
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 OrderID
{
get
{
return _OrderID;
}
set
{
if (_OrderID != value)
{
OnOrderIDChanging(value);
ReportPropertyChanging("OrderID");
_OrderID = StructuralObject.SetValidValue(value);
ReportPropertyChanged("OrderID");
OnOrderIDChanged();
}
}
}
private global::System.Int32 _OrderID;
partial void OnOrderIDChanging(global::System.Int32 value);
partial void OnOrderIDChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 CustomerID
{
get
{
return _CustomerID;
}
set
{
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=true)]
[DataMemberAttribute()]
public Nullable<global::System.Int32> SalesPersonID
{
get
{
return _SalesPersonID;
}
set
{
OnSalesPersonIDChanging(value);
ReportPropertyChanging("SalesPersonID");
_SalesPersonID = StructuralObject.SetValidValue(value);
ReportPropertyChanged("SalesPersonID");
OnSalesPersonIDChanged();
}
}
private Nullable<global::System.Int32> _SalesPersonID;
partial void OnSalesPersonIDChanging(Nullable<global::System.Int32> value);
partial void OnSalesPersonIDChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public Nullable<global::System.Decimal> OrderAmount
{
get
{
return _OrderAmount;
}
set
{
OnOrderAmountChanging(value);
ReportPropertyChanging("OrderAmount");
_OrderAmount = StructuralObject.SetValidValue(value);
ReportPropertyChanged("OrderAmount");
OnOrderAmountChanged();
}
}
private Nullable<global::System.Decimal> _OrderAmount;
partial void OnOrderAmountChanging(Nullable<global::System.Decimal> value);
partial void OnOrderAmountChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public Nullable<global::System.Decimal> SalesTax
{
get
{
return _SalesTax;
}
set
{
OnSalesTaxChanging(value);
ReportPropertyChanging("SalesTax");
_SalesTax = StructuralObject.SetValidValue(value);
ReportPropertyChanged("SalesTax");
OnSalesTaxChanged();
}
}
private Nullable<global::System.Decimal> _SalesTax;
partial void OnSalesTaxChanging(Nullable<global::System.Decimal> value);
partial void OnSalesTaxChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public Nullable<global::System.Int32> OrderStatusID
{
get
{
return _OrderStatusID;
}
set
{
OnOrderStatusIDChanging(value);
ReportPropertyChanging("OrderStatusID");
_OrderStatusID = StructuralObject.SetValidValue(value);
ReportPropertyChanged("OrderStatusID");
OnOrderStatusIDChanged();
}
}
private Nullable<global::System.Int32> _OrderStatusID;
partial void OnOrderStatusIDChanging(Nullable<global::System.Int32> value);
partial void OnOrderStatusIDChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public Nullable<global::System.DateTime> OrderDate
{
get
{
return _OrderDate;
}
set
{
OnOrderDateChanging(value);
ReportPropertyChanging("OrderDate");
_OrderDate = StructuralObject.SetValidValue(value);
ReportPropertyChanged("OrderDate");
OnOrderDateChanged();
}
}
private Nullable<global::System.DateTime> _OrderDate;
partial void OnOrderDateChanging(Nullable<global::System.DateTime> value);
partial void OnOrderDateChanged();
#endregion
#region Navigation Properties
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[XmlIgnoreAttribute()]
[SoapIgnoreAttribute()]
[DataMemberAttribute()]
[EdmRelationshipNavigationPropertyAttribute("OrdersModel", "FK_Orders_Customers", "Customers")]
public Customer Customer
{
get
{
return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Customer>("OrdersModel.FK_Orders_Customers", "Customers").Value;
}
set
{
((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Customer>("OrdersModel.FK_Orders_Customers", "Customers").Value = value;
}
}
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[BrowsableAttribute(false)]
[DataMemberAttribute()]
public EntityReference<Customer> CustomerReference
{
get
{
return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Customer>("OrdersModel.FK_Orders_Customers", "Customers");
}
set
{
if ((value != null))
{
((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<Customer>("OrdersModel.FK_Orders_Customers", "Customers", value);
}
}
}
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[XmlIgnoreAttribute()]
[SoapIgnoreAttribute()]
[DataMemberAttribute()]
[EdmRelationshipNavigationPropertyAttribute("OrdersModel", "FK_OrderDetails_Orders", "OrderDetails")]
public EntityCollection<OrderDetail> OrderDetails
{
get
{
return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<OrderDetail>("OrdersModel.FK_OrderDetails_Orders", "OrderDetails");
}
set
{
if ((value != null))
{
((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection<OrderDetail>("OrdersModel.FK_OrderDetails_Orders", "OrderDetails", value);
}
}
}
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[XmlIgnoreAttribute()]
[SoapIgnoreAttribute()]
[DataMemberAttribute()]
[EdmRelationshipNavigationPropertyAttribute("OrdersModel", "FK_Orders_SalesPerson", "SalesPerson")]
public SalesPerson SalesPerson
{
get
{
return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<SalesPerson>("OrdersModel.FK_Orders_SalesPerson", "SalesPerson").Value;
}
set
{
((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<SalesPerson>("OrdersModel.FK_Orders_SalesPerson", "SalesPerson").Value = value;
}
}
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[BrowsableAttribute(false)]
[DataMemberAttribute()]
public EntityReference<SalesPerson> SalesPersonReference
{
get
{
return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<SalesPerson>("OrdersModel.FK_Orders_SalesPerson", "SalesPerson");
}
set
{
if ((value != null))
{
((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<SalesPerson>("OrdersModel.FK_Orders_SalesPerson", "SalesPerson", value);
}
}
}
#endregion
}
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmEntityTypeAttribute(NamespaceName="OrdersModel", Name="OrderDetail")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class OrderDetail : EntityObject
{
#region Factory Method
/// <summary>
/// Create a new OrderDetail object.
/// </summary>
/// <param name="orderDetailID">Initial value of the OrderDetailID property.</param>
/// <param name="orderID">Initial value of the OrderID property.</param>
/// <param name="itemID">Initial value of the ItemID property.</param>
/// <param name="quantity">Initial value of the Quantity property.</param>
public static OrderDetail CreateOrderDetail(global::System.Int32 orderDetailID, global::System.Int32 orderID, global::System.Int32 itemID, global::System.Int32 quantity)
{
OrderDetail orderDetail = new OrderDetail();
orderDetail.OrderDetailID = orderDetailID;
orderDetail.OrderID = orderID;
orderDetail.ItemID = itemID;
orderDetail.Quantity = quantity;
return orderDetail;
}
#endregion
#region Primitive Properties
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 OrderDetailID
{
get
{
return _OrderDetailID;
}
set
{
if (_OrderDetailID != value)
{
OnOrderDetailIDChanging(value);
ReportPropertyChanging("OrderDetailID");
_OrderDetailID = StructuralObject.SetValidValue(value);
ReportPropertyChanged("OrderDetailID");
OnOrderDetailIDChanged();
}
}
}
private global::System.Int32 _OrderDetailID;
partial void OnOrderDetailIDChanging(global::System.Int32 value);
partial void OnOrderDetailIDChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 OrderID
{
get
{
return _OrderID;
}
set
{
OnOrderIDChanging(value);
ReportPropertyChanging("OrderID");
_OrderID = StructuralObject.SetValidValue(value);
ReportPropertyChanged("OrderID");
OnOrderIDChanged();
}
}
private global::System.Int32 _OrderID;
partial void OnOrderIDChanging(global::System.Int32 value);
partial void OnOrderIDChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 ItemID
{
get
{
return _ItemID;
}
set
{
OnItemIDChanging(value);
ReportPropertyChanging("ItemID");
_ItemID = StructuralObject.SetValidValue(value);
ReportPropertyChanged("ItemID");
OnItemIDChanged();
}
}
private global::System.Int32 _ItemID;
partial void OnItemIDChanging(global::System.Int32 value);
partial void OnItemIDChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 Quantity
{
get
{
return _Quantity;
}
set
{
OnQuantityChanging(value);
ReportPropertyChanging("Quantity");
_Quantity = StructuralObject.SetValidValue(value);
ReportPropertyChanged("Quantity");
OnQuantityChanged();
}
}
private global::System.Int32 _Quantity;
partial void OnQuantityChanging(global::System.Int32 value);
partial void OnQuantityChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public Nullable<global::System.Decimal> UnitPrice
{
get
{
return _UnitPrice;
}
set
{
OnUnitPriceChanging(value);
ReportPropertyChanging("UnitPrice");
_UnitPrice = StructuralObject.SetValidValue(value);
ReportPropertyChanged("UnitPrice");
OnUnitPriceChanged();
}
}
private Nullable<global::System.Decimal> _UnitPrice;
partial void OnUnitPriceChanging(Nullable<global::System.Decimal> value);
partial void OnUnitPriceChanged();
#endregion
#region Navigation Properties
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[XmlIgnoreAttribute()]
[SoapIgnoreAttribute()]
[DataMemberAttribute()]
[EdmRelationshipNavigationPropertyAttribute("OrdersModel", "FK_OrderDetails_Items", "Items")]
public Item Item
{
get
{
return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Item>("OrdersModel.FK_OrderDetails_Items", "Items").Value;
}
set
{
((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Item>("OrdersModel.FK_OrderDetails_Items", "Items").Value = value;
}
}
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[BrowsableAttribute(false)]
[DataMemberAttribute()]
public EntityReference<Item> ItemReference
{
get
{
return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Item>("OrdersModel.FK_OrderDetails_Items", "Items");
}
set
{
if ((value != null))
{
((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<Item>("OrdersModel.FK_OrderDetails_Items", "Items", value);
}
}
}
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[XmlIgnoreAttribute()]
[SoapIgnoreAttribute()]
[DataMemberAttribute()]
[EdmRelationshipNavigationPropertyAttribute("OrdersModel", "FK_OrderDetails_Orders", "Orders")]
public Order Order
{
get
{
return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Order>("OrdersModel.FK_OrderDetails_Orders", "Orders").Value;
}
set
{
((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Order>("OrdersModel.FK_OrderDetails_Orders", "Orders").Value = value;
}
}
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[BrowsableAttribute(false)]
[DataMemberAttribute()]
public EntityReference<Order> OrderReference
{
get
{
return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Order>("OrdersModel.FK_OrderDetails_Orders", "Orders");
}
set
{
if ((value != null))
{
((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedReference<Order>("OrdersModel.FK_OrderDetails_Orders", "Orders", value);
}
}
}
#endregion
}
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmEntityTypeAttribute(NamespaceName="OrdersModel", Name="SalesPerson")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class SalesPerson : EntityObject
{
#region Factory Method
/// <summary>
/// Create a new SalesPerson object.
/// </summary>
/// <param name="salesPersonID">Initial value of the SalesPersonID property.</param>
public static SalesPerson CreateSalesPerson(global::System.Int32 salesPersonID)
{
SalesPerson salesPerson = new SalesPerson();
salesPerson.SalesPersonID = salesPersonID;
return salesPerson;
}
#endregion
#region Primitive Properties
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 SalesPersonID
{
get
{
return _SalesPersonID;
}
set
{
if (_SalesPersonID != value)
{
OnSalesPersonIDChanging(value);
ReportPropertyChanging("SalesPersonID");
_SalesPersonID = StructuralObject.SetValidValue(value);
ReportPropertyChanged("SalesPersonID");
OnSalesPersonIDChanged();
}
}
}
private global::System.Int32 _SalesPersonID;
partial void OnSalesPersonIDChanging(global::System.Int32 value);
partial void OnSalesPersonIDChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.String FirstName
{
get
{
return _FirstName;
}
set
{
OnFirstNameChanging(value);
ReportPropertyChanging("FirstName");
_FirstName = StructuralObject.SetValidValue(value, true);
ReportPropertyChanged("FirstName");
OnFirstNameChanged();
}
}
private global::System.String _FirstName;
partial void OnFirstNameChanging(global::System.String value);
partial void OnFirstNameChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.String LastName
{
get
{
return _LastName;
}
set
{
OnLastNameChanging(value);
ReportPropertyChanging("LastName");
_LastName = StructuralObject.SetValidValue(value, true);
ReportPropertyChanged("LastName");
OnLastNameChanged();
}
}
private global::System.String _LastName;
partial void OnLastNameChanging(global::System.String value);
partial void OnLastNameChanged();
#endregion
#region Navigation Properties
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[XmlIgnoreAttribute()]
[SoapIgnoreAttribute()]
[DataMemberAttribute()]
[EdmRelationshipNavigationPropertyAttribute("OrdersModel", "FK_Orders_SalesPerson", "Orders")]
public EntityCollection<Order> Orders
{
get
{
return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<Order>("OrdersModel.FK_Orders_SalesPerson", "Orders");
}
set
{
if ((value != null))
{
((IEntityWithRelationships)this).RelationshipManager.InitializeRelatedCollection<Order>("OrdersModel.FK_Orders_SalesPerson", "Orders", value);
}
}
}
#endregion
}
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmEntityTypeAttribute(NamespaceName="OrdersModel", Name="sysdiagram")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class sysdiagram : EntityObject
{
#region Factory Method
/// <summary>
/// Create a new sysdiagram object.
/// </summary>
/// <param name="name">Initial value of the name property.</param>
/// <param name="principal_id">Initial value of the principal_id property.</param>
/// <param name="diagram_id">Initial value of the diagram_id property.</param>
public static sysdiagram Createsysdiagram(global::System.String name, global::System.Int32 principal_id, global::System.Int32 diagram_id)
{
sysdiagram sysdiagram = new sysdiagram();
sysdiagram.name = name;
sysdiagram.principal_id = principal_id;
sysdiagram.diagram_id = diagram_id;
return sysdiagram;
}
#endregion
#region Primitive Properties
/// <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.Int32 principal_id
{
get
{
return _principal_id;
}
set
{
Onprincipal_idChanging(value);
ReportPropertyChanging("principal_id");
_principal_id = StructuralObject.SetValidValue(value);
ReportPropertyChanged("principal_id");
Onprincipal_idChanged();
}
}
private global::System.Int32 _principal_id;
partial void Onprincipal_idChanging(global::System.Int32 value);
partial void Onprincipal_idChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 diagram_id
{
get
{
return _diagram_id;
}
set
{
if (_diagram_id != value)
{
Ondiagram_idChanging(value);
ReportPropertyChanging("diagram_id");
_diagram_id = StructuralObject.SetValidValue(value);
ReportPropertyChanged("diagram_id");
Ondiagram_idChanged();
}
}
}
private global::System.Int32 _diagram_id;
partial void Ondiagram_idChanging(global::System.Int32 value);
partial void Ondiagram_idChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public Nullable<global::System.Int32> version
{
get
{
return _version;
}
set
{
OnversionChanging(value);
ReportPropertyChanging("version");
_version = StructuralObject.SetValidValue(value);
ReportPropertyChanged("version");
OnversionChanged();
}
}
private Nullable<global::System.Int32> _version;
partial void OnversionChanging(Nullable<global::System.Int32> value);
partial void OnversionChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.Byte[] definition
{
get
{
return StructuralObject.GetValidValue(_definition);
}
set
{
OndefinitionChanging(value);
ReportPropertyChanging("definition");
_definition = StructuralObject.SetValidValue(value, true);
ReportPropertyChanged("definition");
OndefinitionChanged();
}
}
private global::System.Byte[] _definition;
partial void OndefinitionChanging(global::System.Byte[] value);
partial void OndefinitionChanged();
#endregion
}
#endregion
}
This is lot of code, but the best thing is that you don't have to write any of it. Entity Framework automatically generates code, adding methods to add / update data in your database. Your business logic will work with this code rather than the database itself.
In the next post we will use this code to develop a functional project.
Thank you.