How to Select Data from different Tables Using Linq
-
2012년 5월 1일 화요일 오후 4:31
Hi,
I have two different tables, I just want to collect data from tables using Linq to SQL Queries.
The tables looks like This
ID Name ImageUrl
Other Table is
ID EmpID CheckInTime CheckOutTime
What I want to Collect data from CheckInTime and want to place it in a that is in a list view
Same thing I want to do it for CheckOutTime And One thing I want to tell is both tables are joined by a FK EmpID with ID.
What Are the suggestions for meI have Used this code
var data = from emp in db.Employees join chk in db.CheckInCheckOuts on emp.ID equals chk.EmpID select new EmployeeCheckInOut { Name = emp.Name, ImageUrl = emp.ImageUrl, CheckIn = emp.CheckInCheckOuts, CheckOut = emp.CheckInCheckOuts };Here the CheckInCheckOuts is another table, I don't how do I access fields of the Other table "CheckInCheckOuts"
Thank you
Ali
모든 응답
-
2012년 5월 1일 화요일 오후 4:44What kind of tables are your talking about? It looks more generic lists to me then some DataTables.
Mitja
-
2012년 5월 1일 화요일 오후 4:56
Mitja,
Kind of Tables, I don't Know but I can Tell you that these are Two table, first Table Have Data in It, Name, ImageUrl I have filled this table with names and ImageUrls And are string type.Other Table is for the CheckInTime And CheckOutTime of the employee.
What I need that when I click on the Image button it Should displays The Current Datetime into the label below the Image button.
So I have Problem accessing my CheckInCheckOut Table because I may not have Idea about.Did you understand what I need to do, if you have more question please ask to me.
Thanks
Ali
- 편집됨 qqaadir 2012년 5월 1일 화요일 오후 4:57
-
2012년 5월 1일 화요일 오후 5:36
if tables are connected with foreign key, then you can retrieve data using following way
var data = from emp in db.Employees Select emp.Name, emp.ImageUrl,emp.CheckInCheckOuts.Intime, emp.CheckInCheckOuts.Outtime;
No need to join in query if they have joins in entites.Hasibul Haque,MCC,MCPD hasibulhaque.com
- 답변으로 제안됨 Alexander SunModerator 2012년 5월 2일 수요일 오전 7:59
- 답변으로 표시됨 Alexander SunModerator 2012년 5월 7일 월요일 오전 3:12
-
2012년 5월 1일 화요일 오후 7:06
Yes this is useful
thank you

