Issue when try to get select count using Linq to SQL

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 except 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 Column1 from training where domain = @domain and username = @username

 

posted @ 2010-06-21 16:39  upzone  阅读(154)  评论(0编辑  收藏  举报