Code: Select all
select e.tradeid
from envs e, assets a
where e.state = 'VER'
and e.atype = 'SWAP'
and e.cid = '12312412515'
and e.tradeid = a.tradeid
group by e.tradeid
having count(distinct a.ccy) = 1
Code: Select all
select e.tradeid, count(distinct a.ccy) as ccy
from envs e, assets a
where e.state = 'VER'
and e.atype = 'SWAP'
and e.cid = '12312412515'
and e.tradeid = a.tradeid
group by e.tradeid
Here is an example LINQ that fails and gives the above error (works if I skip the .Distinct() part):ORA-00904: T1.TRADEID: invalid identifier
Code: Select all
.. = from e in _context.Envs
where e.State == "VER" && e.Type == "SWAP" && e.Cid == custID
join a in _context.Assets on e.Tradeid equals a.Tradeid into ae
select new { e.Tradeid, Ccy = ae.Select(n => n.Ccy).Distinct().Count() };
I read somewhere that you need to create your own IEqualityComparer for the Distinct method to work but I think it's an unacceptable overhead to create one for each and every query including the distinct call.
Note: The tables we are reading from are on two different schemas accessed with read-only permissions and will stay that way.
So I guess this comes down to three questions:
1) How would you make the original query work in LINQ (if possible)?
2) Is LINQ2SQL suitable for applications like this, with complicated sql queries? DBMonitor showed me how some of those queries look like and it seems to generate pretty bad inner queries and stuff that normally would make performance suffer. Also, the readability of the LINQ query code is worse than the SQL version
3) There are cases where LINQ suits perfectly so we don´t want to drop it entirely just if it can´t handle the more complex queries. Is there a way for us to perform sql-string queries directly on our context? I´ve tried creating a custom method in the entityframework and it didn't work since it wasn´t possible to make the function return a table or a list of values.
Thanks