[OperationContract]
public List
{
DataClassesDBDataContext db = new DataClassesDBDataContext();
var mlocations = from location in db.locations
select location;
return mlocations.ToList();
}
}
}
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Priya LingePosted Jul 15, 2011, 2:16 AM
You can display one column from table like following way,
Make one class at service side.
suppose EmplyoeeClass
public class Employee
{
private string _name;
public string Name
{
get{return this._name;}
set{if(this._name!=value){this._name=value;}}
}
}
Use this class here to get column.
[OperationContract]
public List
{
List<Employee> emp = new List<Employee>();
con.Open();
string query = "select Name from EmplyoeeData";
cmd=new sqlcommand(query,con);
dr = cmd.ExecuteReader();
while(dr.Read())
{
var trx = new Employee
{
Name=dr[0].ToString()
}
emp.Add(trx);
}
con.Close();
return emp;
}
}
In Linq To Sql
[OperationContract]
public List
{
List
DataClasses1DataContext db = new DataClasses1DataContext();
var result=from e in db.EmployeeDatas order by e.Name select e.Name;
foreach(string str in result)
{
var trn=new Employee
{
Name = str
};
emplist.Add(trn);
}
return emplist;
}
Please check attached file.
Thanks.
Benjamin KemnerPosted Jul 15, 2011, 2:14 AM