Click here to Skip to main content
13,198,850 members (42,720 online)
Click here to Skip to main content

Stats

100.3K views
1.6K downloads
202 bookmarked
Posted 4 Mar 2009

LINQ FAQ for Newbies

, 17 Jul 2009
A LINQ FAQ for newbies.
WindowsFormsLINQQuery
WindowsFormsLINQQuery
bin
Debug
Release
WindowsFormsLINQQuery.exe
WindowsFormsLINQQuery.vshost.exe
WindowsFormsLINQQuery.vshost.exe.manifest
obj
Debug
Refactor
TempPE
Release
Refactor
TempPE
Properties
WindowsFormsLINQQuery.csproj.user
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsLINQQuery
{
    public partial class frmLINQQuery : Form
    {
        public frmLINQQuery()
        {
            InitializeComponent();
        }

        private void btnFireQuery_Click(object sender, EventArgs e)
        {
           
        }

        private void cmbFireQuery_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbFireQuery.SelectedIndex == 0)
            {
                SimpleQuery();
            }
            else if (cmbFireQuery.SelectedIndex == 1)
            {
                FireQueryWithWhere(txtCustomerCode.Text);
            }
            else if (cmbFireQuery.SelectedIndex == 2)
            {
                FireWithJoin();
            }
            else if (cmbFireQuery.SelectedIndex == 3)
            {
                FireWithGroupBy();
            }
            else if (cmbFireQuery.SelectedIndex == 4)
            {
                FireWithOrderBy();
            }
        }
        private void SimpleQuery()
        {
            clsLINQ objLinq = new clsLINQ();
            lstResults.Items.Clear();
            LoadCustomersinList(objLinq.FireSimpleQuery());
        }
        private void FireQueryWithWhere(string strCustomerCode)
        {
            clsLINQ objLinq = new clsLINQ();
            lstResults.Items.Clear();
            LoadCustomersinList(objLinq.FireQueryWithWhere(strCustomerCode));
        }
        private void FireWithJoin()
        {
            clsLINQ objLinq = new clsLINQ();
            lstResults.Items.Clear();
            LoadCustomersinList(objLinq.FireQueryWithJoin());
        }
        private void FireWithGroupBy()
        {
            clsLINQ objLinq = new clsLINQ();
            lstResults.Items.Clear();
            objLinq.FireQueryWithGroupBy(lstResults);
        }
        private void FireWithOrderBy()
        {
            clsLINQ objLinq = new clsLINQ();
            lstResults.Items.Clear();
            LoadCustomersinList(objLinq.FireQueryWithOrderBy());
        }
        private void LoadCustomersinList(IEnumerable<clsCustomer> objCollection)
        {
            foreach (clsCustomer obj in objCollection)
            {
                lstResults.Items.Add(" Name :-"  + obj.CustomerName + " Code  :-" + obj.customerCode + " City  :-" + obj.City);
                foreach (clsOrder objOrder in obj.Orders)
                {
                    lstResults.Items.Add("-->" + objOrder.ProductName);
                }
            }
        }

    }
}

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)

Share

About the Author


You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171020.1 | Last Updated 18 Jul 2009
Article Copyright 2009 by Shivprasad koirala
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid