Context.Query used in generation of EXISTS clause

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
crazypit
Posts: 163
Joined: Wed 15 Apr 2009 08:43

Context.Query used in generation of EXISTS clause

Post by crazypit » Mon 12 Apr 2010 15:19

Hello,

I use the latest stable version of dotConnect for Oracle. When i run the following query, i get an exception.

(from objCustomer in dataContext.Customers
where
(dataContext.Query(
"SELECT cu_id FROM vw_root_cu_code where root_par_code = '10385888'").Select(
a => a)).Contains(objCustomer.Id)
select objCustomer).ToList()

ArgumentNullException
Value cannot be null.
Parameter name: key

What i'm trying to do is to generate this simple SQL:

SELECT A.* FROM CUSTOMERS A WHERE EXISTS (SELECT VW.CU_ID FROM VW_ROOT_CODE VW WHERE VW.ROOT_PAR_CODE = '10385888' AND VW.CU_ID = A.CU_ID)

ATTENTION! I don't have the option to generate an Entity for the view, because it is created dynamically through configuration by the application user, therefore the use of the Query method is mandatory and i cannot project to a specific Entity.

I really don't understand the need for that when generating an EXISTS clause. There is not a requirement to know the structure of the inner table. It can be anything, as long as i provide a Name with an alias plus the key column name prefixed with the alias...

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Wed 14 Apr 2010 13:33

The approach you are using is valid, I have reproduced the problem in our code.
I will let you know as soon as it is fixed.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Wed 28 Apr 2010 08:28

There is a workaround in this case. Use the following code:

Code: Select all

(from objCustomer in dataContext.Customers 
where 
(dataContext.Query( 
"SELECT cu_id as \"c1\" FROM vw_root_cu_code where root_par_code = '10385888'").Select( 
a => a)).Contains(objCustomer.Id) 
select objCustomer).ToList()
This code will work in the next build.

crazypit
Posts: 163
Joined: Wed 15 Apr 2009 08:43

Post by crazypit » Wed 28 Apr 2010 09:02

I already have an other workaround.

Will wait for the proper implementation in the next build. Thanks!

crazypit
Posts: 163
Joined: Wed 15 Apr 2009 08:43

Post by crazypit » Thu 01 Jul 2010 15:46

Is this one fixed in version 5.70?

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Fri 02 Jul 2010 09:59

Yes, this problem was fixed in the 5.70.140 build of dotConnect for Oracle.

Post Reply