Reputation: 4393
I have a simple a join that I want to do but it's not compilng:
private IEnumerable<decimal> GetSampleListOfIds()
{
var samplelList = new List<decimal>
{
100200m,
200200m,
300200m,
400200m,
500200m,
600200m,
700200m,
800200m,
900200m,
1000200m,
1100200m,
1200200m,
1300200m,
1400200m,
1500200m,
1600200m,
1700200m,
1800200m,
1900200m,
2000200m,
};
return samplelList;
}
}
[Test]
public void TestGetIds()
{
var listOfClientIds = GetSampleListOfIds();
var resultSet = from c in _container.ClientIDs
join l in listOfClientIds on c.ClientGUID == l
select c.[some useful attribute]
}
That's basically the gist of it, but its no compiling on 'l' and c.ClientGUID is a nullable type. I tried the obvious stuff, but l is not being recognized a decimal type object from listOfClientIds list.
Do i need to use the into keyword, I have done stuff similar to this before but this has really thrown me off.
Can you anyone solve this compilation error? I bet I have missed or done something stupid.
Upvotes: 0
Views: 186
Reputation: 23011
Try this:
var resultSet = from c in _container.ClientID
join l in listOfClientIds on c.ClientGUID equals l
select c.[some useful attribute]
The join clause compares the specified keys for equality by using the special equals keyword. (http://msdn.microsoft.com/de-de/library/bb311040.aspx)
You can also do it without using join:
var resultSet = from c in _container.ClientID
where listOfClientIds.Contains(c.ClientGUID)
select c.[some useful attribute]
Upvotes: 1
Reputation: 236268
var resultSet = from c in _container.ClientID
where listOfClientIds.Any(l => c.ClientGUID.Contains(l))
select c.[some useful attribute];
NOTE: I suggest you to improve naming - ClientID
looks like single value holding client ID (at least not sequence of ids). ClientGUID
also looks like single value of Guid
type. I would expect Clients
and Ids
instead.
Upvotes: 1