Reputation: 93
Please help me out. I have 2 tables and I need to use lambda. The first table needs to be retrieved, but the first and second table has the where part in.
example
public class tableone
{
public string Name;
public string Surname;
public int DepartmentNumber;
public string GroupId;
}
public class Group
{
public string groupId;
public string BaseName;
public string BaseSiteName;
}
I need to retrieve the Table one field but with using a where clause of DepartmentNumber and BaseSite
I think I got this part. I have the entity test and
var records = test.tableone.join(test.Group, group => group.groupId, tableone => tableone.GroupId,
(group, testone) => new {tableone = tableOne, group = grouptable});
I am not sure if that is correct. How can I retrieve one the table one part. Any help will be apprecaited.
Upvotes: 1
Views: 77
Reputation: 48
If the code you show is working you can just add the filtering and pull out the table one records like this:
var filteredRecords = records
.Where(r => r.tableone.DepartmentNumber == 5 && r.group.BaseSiteName == "Whatever")
.Select(r => r.tableone);
You can also filter the tables you are joining before hand:
var filteredTableOnes = tableone.Where(t => t.DepartmentNumber == 5);
var filteredGroup = group.Where(g => g.BaseSiteName == "Whatever");
Upvotes: 1