When a null field is found in the Linq query condition, the following error occurs: variable' & lt; & gt; h _ TransparentIdentifier2 'of type referenced from scope '', but it is not defined, linqtosql.

Source: Internet
Author: User

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}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.