Click here to Skip to main content
12,069,450 members (67,064 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: WCF LINQ
hi all,

i have a sql table(emp_id,ename,e_sal).now i want to inserting some rows through the client application.
here i need to create a wcf service to inserting the data into sqldatabase through the LINQ for that how can create a wcf service to inserting the data into sqlDB.

note: this service has three inserting parameters are(emp_id,ename,e_sal).

please any body help to me.
thanks in advance.......

thanks and regards,
naresh
Posted 21-May-12 21:46pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

you can make this:

[DataContract]
public class Employee
{
  [DataMember]
  public int Id;
 
  [DataMember]
  public string Name;
 
  [DataMember]
  public decimal Salary;
}
 
[ServiceContract]
public interface IService
{
  [OperationContract]
  void AddEmployee(Employee employee);
}

Implement method AddEmployee in server and just call it from client. Client should now nothing about SQL, otherwise its no point to make WCF.

As for insert phase implementation it has nothing to do with WCF. Refer to LinqToSQL using-linq-to-sql-part-1 or Simple-LINQ-to-SQL-in-C

If you have DataContext then you can do following:
// connect
MyDataCotext db = new MyDataCotext();
 
// generate new record
EmployeeRecord/*(this is what comes from DBContext)  */ emp = new EmployeeRecord();
 
// assign values
emp.Id = Employee.Id
emp.Name = Employee.Name
emp.Salary = Employee.Salary
 
// add to database
db.EmployeeRecords.Add(emp);
db.SubmitChanges();
  Permalink  
v3
Comments
Unareshraju 22-May-12 3:15am
   
hi shawnas thanks to u r reply,
i was connected to database through the LINQ for that no need to declare data contract,
i am inserting the values through the my application(wpf in that text boxes) .please any help how write insert command when i am inserting values through the my application

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web04 | 2.8.160208.1 | Last Updated 22 May 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100