Sunday, 11 March 2012

edmx


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.EnterpriseServices;
using System.Data.EntityModel;
using jayModel;
using System.Data.Linq.SqlClient;

public partial class Default2 : System.Web.UI.Page
{
/*name of entity class is jay*/
    jayEntities j = new jayEntities();
    Table1 t = new Table1();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        int i = Convert.ToInt32(TextBox1.Text);

       
        /* If where condition for one field  Require using query */
     
        var a = j.Table1.Where(m => m.id == i).ToList().Select(m => m.name);
       
     
        GridView1.DataSource = a;
        GridView1.DataBind();

        /* if where condition  require */
 /*here name start with h and contain c  */
        var d1 = j.Table1.Where(f => f.name.StartsWith("h")&& f.name.Contains("c")).Select(f=>f.name);
     
        /*Display two field
       
        //var d1 = j.Table1.Select(f => new { f.id,f.name}).OrderBy(f=>f.name).Where(f=>f.id==i);
     //  var d4 = j.Table1.Select(f => new { f.name });*/

        GridView2.DataSource = d1;
        GridView2.DataBind();
        /*All Table Data */
        var d2 = j.Table1.ToList();
        GridView3.DataSource = d2;
        GridView3.DataBind();
        /*If where condition for two field  Require */


        //List<jayModel.Table1> list = new List<jayModel.Table1>();
        var list = j.Table1.Where(m => m.id == i).ToList();
        //var list1 = j.count_tbl.Where(m => m.id == i).ToList();
        var objJoin = list.Join(list, b => b.id, c => c.id, (b, c) => new { name = b.name, address = b.Address });
        //left outer join using edmx
        var q = from t1 in j.Table1
                join t2 in j.count_tbl on t1.id equals t2.id into t1t2
                from t2 in t1t2.DefaultIfEmpty()
                select new { t1.id, t1.name };
        //right outer join using edmx
        var q1 = from t2 in j.count_tbl join t1 in j.Table1 on t2.id equals t1.id into t1t2 from t1 in t1t2.DefaultIfEmpty() select new { t2.month, t2.number, t1.name };

        GridView4.DataSource = q1;
        GridView4.DataBind();
    }
}

No comments:

Post a Comment