Parameter Problem when Using Union

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
daveoggy
Posts: 14
Joined: Fri 23 Jan 2009 18:15

Parameter Problem when Using Union

Post by daveoggy » Sun 11 Jul 2010 17:56

I have the following code which I think exposes a bug:

Code: Select all

            Dictionary> Lookup = new Dictionary>();
            Lookup.Add(200, new List() { 0, 1, 2 });
            Lookup.Add(330, new List() { 0, 1, 4 });

            using (Entities ent = new Entities())
            {
                IQueryable query = null;
                foreach (var x in Lookup)
                {
                    var queryPart = from t in ent.TM_FNET
                                    where t.ACTION.Value == x.Key
                                    && x.Value.Contains(t.STATUS.Value)
                                    select t.ID;

                    //first one becomes the main query, subsequent ones union-ed on...
                    if (query == null)
                        query = queryPart;
                    else
                        query = query.Union(queryPart);
                }

                foreach (var f in query.ToList())
                {
                    Console.WriteLine("{0}", f);
                }
            }
Which results in the following SQL statement:

Code: Select all

SELECT 
"Distinct1".C1 AS C1
FROM ( SELECT DISTINCT 
	"UnionAll1".ID AS C1
	FROM  (SELECT 
		"Extent1".ID AS ID
		FROM TMDDBA.TM_FNET "Extent1"
		WHERE ("Extent1".ACTION = :p__linq__0) AND (((0 = "Extent1".STATUS) OR (1 = "Extent1".STATUS)) OR (4 = "Extent1".STATUS))
	UNION ALL
		SELECT 
		"Extent2".ID AS ID
		FROM TMDDBA.TM_FNET "Extent2"
		WHERE ("Extent2".ACTION = :p__linq__1) AND (((0 = "Extent2".STATUS) OR (1 = "Extent2".STATUS)) OR (4 = "Extent2".STATUS))) "UnionAll1"
)  "Distinct1"
All is well expect for the values assigned to the parameters :p_linq_0 and p_linq_1, for some reason both of these values are 330.

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

Post by AndreyR » Mon 12 Jul 2010 15:15

I have reproduced this issue as well. The investigation is in progress.
I will notify you about the results of our investigation as soon as possible.

daveoggy
Posts: 14
Joined: Fri 23 Jan 2009 18:15

Post by daveoggy » Fri 16 Jul 2010 16:38

Thanks AndreyR, any progress?

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

Post by AndreyR » Wed 21 Jul 2010 15:57

Our investigation is in progress, sorry for the delay.
I will post here as soon as the results are available.

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

Post by AndreyR » Fri 23 Jul 2010 14:58

This situation is a bit more complicated.
In fact, everything goes correct.
The binding of the EF parameter occurs at the moment you materialize the query, not at the moment when query is initialized.
So, value of x.Key is taken from the latest foreach iteration. This is a designed behaviour, the solution is to use different variables for different parameters.

Post Reply