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