How to Select Data from different Tables Using Linq
-
martedì 1 maggio 2012 16: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
Tutte le risposte
-
martedì 1 maggio 2012 16:44What kind of tables are your talking about? It looks more generic lists to me then some DataTables.
Mitja
-
martedì 1 maggio 2012 16: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
- Modificato qqaadir martedì 1 maggio 2012 16:57
-
martedì 1 maggio 2012 17: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
- Proposto come risposta Alexander SunModerator mercoledì 2 maggio 2012 07:59
- Contrassegnato come risposta Alexander SunModerator lunedì 7 maggio 2012 03:12
-
martedì 1 maggio 2012 19:06
Yes this is useful
thank you

