Laxmi Katti

Laxmi Katti

  • NA
  • 25
  • 5.5k

Get data from multiple table by using single func in webapi

Jul 15 2018 11:55 PM
 I have to write a single query or stored procedure or function which can display all tables data using ASP.Net WEB API.
Please help me to to find solution. 
 
public class StudentController : ApiController
{
EmployeeDbEntities1 entities=new EmployeeDbEntities1();
public IEnumerable<Students> Get()
{
List<Students> ListStud = new List<Students>();
var query = (from a in entities.tblstudents
select a).ToList();
query.ForEach(s =>
{
ListStud.Add(new Students
{
StudId = s.StudentId,
StudName = s.Name,
StudAdd = s.Address,
StudGender = s.Gender,
StudStd = s.Standard
}
);
}
);
return ListStud;
}
 
[Route("~/api/User")]
public List<User> get()
{
List<User> users = new List<User>();
var query = (from a in entities.tblUsers
select a).ToList();
query.ForEach(u =>
users.Add(new User { username = u.UserName, password = u.Password }
)
);
return users;
}
 

Answers (4)