Issue when try to get select count using LINQ to SQL

Source: Internet
Author: User

Issue:

Database SP:

Select count (*) from training where domain = @ domain and username = @ username

LINQ: trainingdatabase. dbml

Main class:

trainingdatabasedatacontext context = new trainingdatabasedatacontext ("Data Source = .; initial catalog = training; Integrated Security = true ");
var Results = context. spgetusercompletion ("psdcrm", "Administrator");
foreach (VAR result in results)
{
If (result. column1.hasvalue & result. column1.value> 0)
{
console. writeline ("true");
}
}

 

I have t to get one line "true", but failed.

 

Cause:

Maybe LINQ cannot map computed column to the column1 entity.

 

Solution:

Try to modify the SP and add the alias column name just like below:

Select count (*)As column1From training where domain = @ domain and username = @ username

 

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.