In SQL you can selecta constant value:
Select "Constant Text", Column1, Column2 From TableX
and each row returned from TableX starts with a column containing the text "Constant Text".
Any ideas on how I can do this in LINQ to SQL?
If I do the above I get the error message "Range variable name can be inferred only from a simple or qualified name with no arguments."
From stackoverflow
-
from tx in dc.TableX select new { "constant text", tx.Column1, tx.Column2 };
-
var db = new DataContext(); var query = from x in db.TableX select new {"Constant Text", x.Column1, x.Column2};
..i think it's something like that.
-
Actually, each property in the resulting anonymous class needs a name, so in the following code, we are naming the constant column
ConstantColumn
. The 2nd and 3rd properties will by default take the names of the queried columns, so they will be namedColumn1
andColumn2
respectively:var query = from x in db.TableX select new { ConstantColumn = "Constant Text", x.Column1, x.Column2 };
0 comments:
Post a Comment