This documentation is archived and is not being maintained.

How to: Define POCO Entities

Visual Studio 2010

The Entity Framework enables you to use your own custom data classes. For more information, see Working with POCO Entities. This topic defines a set of POCO types that are implicitly mapped, by having the same type and property names, to the data model that is defined in How to: Customize Modeling and Mapping Files to Work with Custom Objects. This model is based on the Contact, SalesOrderHeader, and SalesOrderDetail tables in the AdventureWorks database. For information on how to define a custom object context class, see How to: Define a Custom Object Context.

Example

This example defines the Contact, Order, LineItem, and OrderInfo custom data classes. These classes have been defined to support proxy object creation. For more information, see Requirements for Creating POCO Proxies.

public class LineItem
{
    public virtual Int32 SalesOrderID { get; set; }
    public virtual Int32 SalesOrderDetailID { get; set; }
    public virtual String CarrierTrackingNumber { get; set; }
    public virtual Int16 OrderQty { get; set; }
    public virtual Int32 ProductID { get; set; }
    public virtual Int32 SpecialOfferID { get; set; }
    public virtual Decimal UnitPrice { get; set; }
    public virtual Decimal UnitPriceDiscount { get; set; }
    public virtual Decimal LineTotal { get; set; }
    public virtual Guid rowguid { get; set; }
    public virtual DateTime ModifiedDate { get; set; }
    // Defines a navigation property to the Order object.
    public virtual Order Order { get; set; }
}

public class Order
{
    public virtual Int32 SalesOrderID { get; set; }
    public virtual Byte RevisionNumber { get; set; }
    public virtual DateTime OrderDate { get; set; }
    public virtual DateTime DueDate { get; set; }
    public virtual Nullable<DateTime> ShipDate { get; set; }
    public virtual Byte Status { get; set; }
    public virtual Boolean OnlineOrderFlag { get; set; }
    public virtual String SalesOrderNumber { get; set; }
    public virtual String PurchaseOrderNumber { get; set; }
    public virtual String AccountNumber { get; set; }
    public virtual Int32 CustomerID { get; set; }
    public virtual Int32 ContactID { get; set; }
    public virtual Nullable<Int32> SalesPersonID { get; set; }
    public virtual Nullable<Int32> TerritoryID { get; set; }
    public virtual Int32 BillToAddressID { get; set; }
    public virtual Int32 ShipToAddressID { get; set; }
    public virtual Int32 ShipMethodID { get; set; }
    public virtual Nullable<Int32> CreditCardID { get; set; }
    public virtual String CreditCardApprovalCode { get; set; }
    public virtual Nullable<Int32> CurrencyRateID { get; set; }
    public virtual Decimal SubTotal { get; set; }
    public virtual Decimal TaxAmt { get; set; }
    public virtual Decimal Freight { get; set; }
    public virtual Decimal TotalDue { get; set; }
    public virtual String Comment { get; set; }
    public virtual Guid rowguid { get; set; }
    public virtual DateTime ModifiedDate { get; set; }
    public virtual OrderInfo ExtendedInfo { get; set; }
    // Defines a navigation property to the collection of LineItem objects.
    public virtual ICollection<LineItem> LineItems { get; set; }
    // Defines a navigation property to the Contact object.
    public virtual Contact Contact { get; set; }
}

public class OrderInfo
{
    public string SalesOrderNumber { get; set; }
    public string PurchaseOrderNumber { get; set; }
    public string AccountNumber { get; set; }
    public string Comment { get; set; }
}

public class Contact
{
    public virtual Int32 ContactID { get; set; }
    public virtual Boolean NameStyle { get; set; }
    public virtual String Title { get; set; }
    public virtual String FirstName { get; set; }
    public virtual String MiddleName { get; set; }
    public virtual String LastName { get; set; }
    public virtual String Suffix { get; set; }
    public virtual String EmailAddress { get; set; }
    public virtual Int32 EmailPromotion { get; set; }
    public virtual String Phone { get; set; }
    public virtual String PasswordHash { get; set; }
    public virtual String PasswordSalt { get; set; }
    public virtual String AdditionalContactInfo { get; set; }
    public virtual Guid rowguid { get; set; }
    public virtual DateTime ModifiedDate { get; set; }
    // Defines a navigation property to the collection of Order objects.
    public virtual ICollection<Order> Orders { get; set; }
}

See Also

Show: