what is the equivalent linq query for the following sql query?
-
string qryInterviews = "SELECT ID, UpdatedByAdmin, UpdatedBy,Deleted " +
"CASE UpdatedByAdmin WHEN 1 THEN Date1 ELSE TimesForDate1 END AS D1, " +
"CASE UpdatedByAdmin WHEN 1 THEN Date2 ELSE TimesForDate2 END AS D2, " +
"CASE UpdatedByAdmin WHEN 1 THEN Date3 ELSE TimesForDate3 END AS D3, " +"FROM myTable where (Deleted is null OR Deleted = 0)";
In the above query, UpdatedByAdmin,Deleted are of tinyInt datatype. Please help.
Dhyanga
-
string qryInterviews = "SELECT ID, UpdatedByAdmin, UpdatedBy,Deleted " +
"CASE UpdatedByAdmin WHEN 1 THEN Date1 ELSE TimesForDate1 END AS D1, " +
"CASE UpdatedByAdmin WHEN 1 THEN Date2 ELSE TimesForDate2 END AS D2, " +
"CASE UpdatedByAdmin WHEN 1 THEN Date3 ELSE TimesForDate3 END AS D3, " +"FROM myTable where (Deleted is null OR Deleted = 0)";
In the above query, UpdatedByAdmin,Deleted are of tinyInt datatype. Please help.
Dhyanga
That doesn't even look like valid SQL.
-
That doesn't even look like valid SQL.
-
That doesn't even look like valid SQL.
var query = (from sub in db.myTable
where (sub.Deleted == null || sub.Deleted == 0)
select new
{
sub.ID,
sub.UpdatedByAdmin,
sub.UpdatedBy,
sub.Deleted,
D1 = sub.UpdatedByAdmin.Equals(true ? sub.Date1 : sub.TimesForDate1),
D2 = sub.UpdatedByAdmin.Equals(true ? sub.Date2 : sub.TimesForDate2),
D3 = sub.UpdatedByAdmin.Equals(true ? sub.Date3 : sub.TimesForDate3)}).ToList();
But this is giving error message as:
System.ArgumentException: DbComparisonExpression requires arguments with comparable types.
I think its because my UpdatedByAdmin, Deleted columns are tinyInt datatype in the database. But When i used these fields in model class, i used byte datatype. I thought byte is equivalent to tinyInt. Please help.
Dhyanga
-
var query = (from sub in db.myTable
where (sub.Deleted == null || sub.Deleted == 0)
select new
{
sub.ID,
sub.UpdatedByAdmin,
sub.UpdatedBy,
sub.Deleted,
D1 = sub.UpdatedByAdmin.Equals(true ? sub.Date1 : sub.TimesForDate1),
D2 = sub.UpdatedByAdmin.Equals(true ? sub.Date2 : sub.TimesForDate2),
D3 = sub.UpdatedByAdmin.Equals(true ? sub.Date3 : sub.TimesForDate3)}).ToList();
But this is giving error message as:
System.ArgumentException: DbComparisonExpression requires arguments with comparable types.
I think its because my UpdatedByAdmin, Deleted columns are tinyInt datatype in the database. But When i used these fields in model class, i used byte datatype. I thought byte is equivalent to tinyInt. Please help.
Dhyanga
Dhyanga wrote:
I thought byte is equivalent to tinyInt.
It is, but SQL tends to be more forgiving than C#.
-
string qryInterviews = "SELECT ID, UpdatedByAdmin, UpdatedBy,Deleted " +
"CASE UpdatedByAdmin WHEN 1 THEN Date1 ELSE TimesForDate1 END AS D1, " +
"CASE UpdatedByAdmin WHEN 1 THEN Date2 ELSE TimesForDate2 END AS D2, " +
"CASE UpdatedByAdmin WHEN 1 THEN Date3 ELSE TimesForDate3 END AS D3, " +"FROM myTable where (Deleted is null OR Deleted = 0)";
In the above query, UpdatedByAdmin,Deleted are of tinyInt datatype. Please help.
Dhyanga
-