When a null field is found in the Linq query condition, the following error occurs: variable' <> h _ TransparentIdentifier2 'of type referenced from scope '', but it is not defined, linqtosql.
This error is reported when I run the following linq query,
1: var result = (from so in svcContext.new_sales_orderSet
2: join soitem in svcContext.new_sales_order_itemSet on so.Id equals soitem.new_sales_orderid.Id
3: join fpitem in svcContext.new_fp_itemSet on soitem.new_modelid.Id equals fpitem.new_modelid.Id
4: join fp in svcContext.new_floor_priceSet on fpitem.new_fp.Id equals fp.Id
5: where so.Id == currentEntity.Id
6: && soitem.new_invoice_price > fpitem.new_floor_price
7: select (soitem.new_invoice_price - fpitem.new_floor_price) * soitem.new_qty
8: ).ToList();
After looking for the reason for half a day, we found that the reason is:
&& soitem.new_invoice_price > fpitem.new_floor_price
Because both fields are Decimal ?, If some values are null, an error is returned when compared.
Remove this condition and add the where condition:
var result = query.Where(q => q != null && q.Value > 0).ToList();
How can I use a date field as a query condition in LINQ?
We recommend that you first initialize a DateTime with the value DateTime. Now minus 30 days.
Then use these two dates for comparison in Linq.
For a multi-Table query using linq, fields are returned. Note: Do not list fields one by one. Do not select new {a, B} to return results.
The answer to this question is the two methods you know. There are only two methods:
Select new {a, B };
Either select new {a. Field 1, a. Field 2, B. Field 1, B. Field 2}