Click here to Skip to main content
Rate this: bad
good
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 20: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 at 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
0 CHill60 320
1 Sarvesh Kumar Gupta 238
2 Sergey Alexandrovich Kryukov 163
3 OriginalGriff 163
4 DamithSL 153


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