Click here to Skip to main content
15,891,567 members
Articles / Desktop Programming / Windows Forms

Entity Framework in WinForms

Rate me:
Please Sign up or sign in to vote.
4.89/5 (142 votes)
28 Jul 2014CPOL29 min read 952.9K   58.1K   425  
A component that makes it easy to use Entity Framework in WinForms projects, including design-time binding support.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sample
{
    /// <summary>
    /// Add a field with total order amount.
    /// </summary>
    public partial class Order
    {
        // calculate amount for this order
        public decimal Amount
        {
            get
            {
                var q = from od in this.Order_Details select od.Amount;
                return q.Sum();
            }
        }
    }
    /// <summary>
    /// Add a field with order detail amount.
    /// </summary>
    public partial class Order_Detail 
    {
        // calculate amount for this order detail
        public decimal Amount
        {
            get { return Quantity * UnitPrice * (1 - (decimal)Discount); }
        }
    }
    /// <summary>
    /// Add a field with the employee's full name
    /// </summary>
    public partial class Employee
    {
        public string FullName
        {
            get
            {
                return string.Format("{0} {1}", FirstName, LastName);
            }
        }
        public override string ToString()
        {
            return FullName;
        }
    }
}

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
Brazil Brazil
Software Architect/Developer with several years experience creating and delivering software.

Full-stack Web development (including React, Firebase, TypeScript, HTML, CSS), Entity Framework, C#, MS SQL Server.

Passionate about new technologies and always keen to learn new things as well as improve on existing skills.

Comments and Discussions