Based on the following tables
Sample
Id Name
---------------
S1 SomeName
S2 OtherName
S3 AnotherName
AlreadyUsed
Id
---------
S2
Reference
Id FkId
---------
T1 S1
T2 S1
I want to achieve the following "select only those entries from Sample table which have no entries in AlreadyUsed and have atleast one entry in Reference table."
I was able to write query for the first part but confused with the second half. Below is what i could come up with to get "select only those entries from sample table which have no entries in AlreadyUsed table"
var count = 50;
var alreayUsed = from au in repository.GetEntity<AlreadyUsed>()
select au.Id;
var notUsed = (from nu in repository.GetEntity<Sample>()
where !alreadyUsed.Contains(nu.Id)
orderby nu.Name
select new CustomClass
{
CName = nu.Name,
CId = nu.Id
}).Take(count).ToArray();
Also pls. suggest if there is a better way to write the above query.
thanks.
"Sample"or"NotUsed"?