I'm working with a colleague and we're trying to reproduce the following SQL Query using LinqToEntities (Entity Framework v4.0)
SELECT t1.*
FROM [dbo].LocaleStringResource AS t1
LEFT OUTER JOIN [dbo].LocaleStringResource AS t2
ON (t1.ResourceName = t2.ResourceName AND t1.AccountId < t2.AccountId)
WHERE t2.ResourceName IS NULL;
Basically it's saying only return us the highest AccountIds where there is more than one matching ResourceName. We have got this so far...
localeStringResource = from e1 in localeStringResource
join e2 in localeStringResource
on new { e1.ResourceName, e1.AccountId } equals new { e2.ResourceName, e2.AccountId }
where e2.ResourceName == null
select e1;
But we don't seem to be able to work out how to achieve the equivalent less than (<) within the LEFT OUTER JOIN?
ON (t1.ResourceName = t2.ResourceName AND t1.AccountId < t2.AccountId)
Could anyone please advise if this is possible or if we're barking up the wrong tree? We have attempted to make the initial query as simple as possible hoping it will make the equivalent LinqToEntities query easier to build.
Note:
AccountId
is not unique. We have an Identity
Id
column on the LocalResourceString
table. However there is a Unique Constraint on both AccountId
and ResourceName