R
RayLopez99
This is more an observation than a question. I notice in the below
the 'catch' is never triggered, even if I enter a value that I know is
not present in MyTable. Thus I know for example the Table column
AField, holding strings, does not have any rows that start with "Z",
but if I input aString = "ZZZZ", I don't get var MyMatchingTables =
null, but rather I get zero hits (or .Count = 0). Must be built into
Linq-to-Sql. I've been using it for years but this is the first time
I thought about it, since I just read somewhere that keyword 'var'
does not support any nulls, or rather the right hand side source
cannot return a null.
RL
public List<MyTable> GetMyTablesByName(string aString)
{
List<MyTable> myMyTableList = new List<MyTable>();
try
{
DataContext database = new
DataContext(MyConnectionString);
var MyMatchingTables = from X in db.MyTables
where
X.AField.StartsWith(aString)
select X;
//why is var MyMatchingTables never null? Must be built into Linq to
Sql to never return null?
myMyTableList =
MyMatchingTables.ToList();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message); //never triggered, even
if no match
}
return myMyTableList;
}
the 'catch' is never triggered, even if I enter a value that I know is
not present in MyTable. Thus I know for example the Table column
AField, holding strings, does not have any rows that start with "Z",
but if I input aString = "ZZZZ", I don't get var MyMatchingTables =
null, but rather I get zero hits (or .Count = 0). Must be built into
Linq-to-Sql. I've been using it for years but this is the first time
I thought about it, since I just read somewhere that keyword 'var'
does not support any nulls, or rather the right hand side source
cannot return a null.
RL
public List<MyTable> GetMyTablesByName(string aString)
{
List<MyTable> myMyTableList = new List<MyTable>();
try
{
DataContext database = new
DataContext(MyConnectionString);
var MyMatchingTables = from X in db.MyTables
where
X.AField.StartsWith(aString)
select X;
//why is var MyMatchingTables never null? Must be built into Linq to
Sql to never return null?
myMyTableList =
MyMatchingTables.ToList();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message); //never triggered, even
if no match
}
return myMyTableList;
}