Performing LINQ Self Join
- by senfo
I'm not getting the results I want for a query I'm writing in LINQ using the following:
var config = (from ic in repository.Fetch()
join oc in repository.Fetch() on ic.Slot equals oc.Slot
where ic.Description == "Input" && oc.Description == "Output"
select new Config
{
InputOid = ic.Oid,
OutputOid = oc.Oid
}).Distinct();
The following SQL returns 53 rows (which is correct), but the above LINQ returns 96 rows:
SELECT DISTINCT
ic.Oid AS InputOid,
oc.Oid AS OutputOid
FROM dbo.Config AS ic
INNER JOIN dbo.Config AS oc ON ic.Slot = oc.Slot
WHERE
ic.Description = 'Input' AND
oc.Description = 'Output'
How would I replicate the above SQL in a LINQ query?
Update: I don't think it matters, but I'm working with LINQ to Entities 4.0.