PassionateDeveloper
PassionateDeveloper

Reputation: 15138

LINQ: Query to get information from 2 tables

I have a PM-Table in which are a SenderID and a ReciID.

Both have a foreign key construct in the MSSQL Table to table User.

How I can get the Information about SenderID.Username and ReciID.Username?

I know there is this method:

DataLoadOptions options = new DataLoadOptions();
            options.LoadWith<Biethistorie>(a => a.Auktion);
            options.LoadWith<Auktion>(a => a.Artikel);
            dc.LoadOptions = options;

But the problem is, the User-table is very large and I only need the 1 information to display (username).

Upvotes: 0

Views: 134

Answers (1)

Arash N
Arash N

Reputation: 324

var query = from emp in dbEmp.Employees
            join dept in dbEmp.Departments
            on emp.DeptID equals dept.DeptID
            select new 
            {
                    EmpID = emp.EmpID,
                    EmpName = emp.EmpName,
                    Age = emp.Age,
                    Address = emp.Address,
                    DeptName = dept.DepartmentName
            };

select new{} gives you only the fields that you choose to return.

Upvotes: 1

Related Questions