I need to add a literal value to the query. My attempt
var aa = new List<long>(); aa.Add(0); var a = Products.Select(p => p.sku).Distinct().Union(aa); a.ToList().Dump();
In the above example, I get an error:
"Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator."
If I use Entity Framework 4, for example, what can I add to the Union statement to always include the identifier "seed"?
I am trying to create SQL code as follows:
select distinct ID from product union select 0 as ID
Thus, I can join list itself so that I can find all the values โโwhere the next highest value is missing (search for the lowest available identifier in the set).
Edit: original Linq query to find the most affordable ID
var skuQuery = Context.Products .Where(p => p.sku > skuSeedStart && p.sku < skuSeedEnd) .Select(p => p.sku).Distinct(); var lowestSkuAvailableList = (from p1 in skuQuery from p2 in skuQuery.Where(a => a == p1 + 1).DefaultIfEmpty() where p2 == 0
This code creates two sets of SKUs offset by one, then selects SKUs where the next maximum does not exist. After that, he chooses the minimum of this (the lowest SKU, where the next maximum is available).
For this to work, the seed must be in a kit connected together.
source share