Parameter Problem when Using Union
Posted: Sun 11 Jul 2010 17:56
I have the following code which I think exposes a bug:
Which results in the following SQL statement:
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.
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);
}
}
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"