Common Causes of exceptions of specified cast is not valid in LINQ Query

Source: Internet
Author: User

I. Cause of exception

"System. invalidcastexception: specified cast is not valid"

The above exception occurs in the query of the LINQ to SQL statement, usually because the field types of the relevant tables in the model file are inconsistent with those of the corresponding tables in the database.

 

II. Solution:

1) check whether the "server data type" attribute value in the field attribute of the relevant table in the model file (. dbml) is consistent with the database field type. If the attribute is inconsistent, modify the attribute value based on the database field type;

2) check whether the "type" attribute value in the field attribute of the relevant table in the model file (. dbml) matches the database field type. If the attribute does not match, it is modified based on the database field type.

 

Tip:

You can narrow the field range according to the description of the data type in the exception stacktrace information.

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.