WCF+LINQ(Integration)
//BL.CS
using System;
using System.Data.Linq.Mapping;
using System.Runtime.Serialization;
[DataContract]
[Table(Name="student")]
public class BL
{
[DataMember]
[Column(Name="seat_no",IsPrimaryKey=true)]
public int sno {get;set;}
[DataMember]
[Column(Name="name")]
public string sn { get; set; }
}
//DAL.CS
using System;
using System.Data.Linq;
using System.Collections.Generic;
using System.Linq;
public class DAL
{
Table<BL> b2 = null;
public List<BL> Show_Data()
{
List<BL> st = new List<BL>(); //For manipulation
// For insert,update,delete
using (DataContext dt = new DataContext("initial
catalog=cac;integrated security=yes;data
source=WINDOWS-PC\\SQLEXPRESS"))
{
st = dt.GetTable<BL>().ToList();
}
return st;
}
public int save(BL b)
{
using (DataContext dt = new DataContext("initial
catalog=cac;integrated security=yes;data
source=WINDOWS-PC\\SQLEXPRESS"))
{
b2 = dt.GetTable<BL>(); //Call By rererence
b2.InsertOnSubmit(b);
dt.SubmitChanges();
return 1;
}
}
}
//Service.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Runtime.InteropServices;
// NOTE: You can use the "Rename" command on the "Refactor" menu to
change the class name "Service" in code, svc and config file together.
public class Service : IService
{
public List<BL> Get_Student()
{
DAL d = new DAL();
return d.Show_Data();
}
public int Save_data(BL b)
{
DAL d2 = new DAL();
d2.save(b);
return 1;
}
}
/IService
//using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
// NOTE: You can use the "Rename" command on the "Refactor" menu to
change the interface name "IService" in both code and config file
together.
[ServiceContract]
public interface IService
{
[OperationContract]
List<BL> Get_Student();
[OperationContract]
int Save_data(BL b);
}
//AT CLIENT SIDE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
ServiceReference1.ServiceClient s = new ServiceReference1.ServiceClient();
GridView1.DataSource = s.Get_Student();
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
int r = Convert.ToInt32(TextBox1.Text);
string n = TextBox2.Text;
ServiceReference1.BL a = new ServiceReference1.BL();
a.sno = r;
a.sn = n;
ServiceReference1.ServiceClient s2 = new ServiceReference1.ServiceClient();
int f=s2.Save_data(a);
if (f == 1)
{
GridView1.DataSource = s2.Get_Student();
GridView1.DataBind();
}
}
}
No comments:
Post a Comment