I had a need to execute a SQL statement using LINQ to SQL. Its a long story, but I couldn't use the LINQ to SQL Designer because I was calling a SQL Server 2005 System View. So, I just decided to use the DataContext.ExecuteQuery method. It was a welcome surprise when the intellisense tooltip filled the screen for the first parameter "elementType" -
Actually, the tooltip really helped. It explains the rules and priority of how the return resultset is mapped to the type you specify. To paraphrase, even though my type doesn't have LINQ to SQL attributes on each property, the system will still attempt to match properties to result columns using a variety of methods.
- If a field or property is matched to a specific column name, that column is expected in the result set
- If the field or property is not matched, a column is expected with the same name in the result set (first Case Sensitive search, then case in-sensitive search)
It goes onto specify the rules about change tracking, primary keys, etc.
A lot to read, but definitely saved me a having to hunt around for the necessary information. Nice work to whoever spent the extra time going to this detail; it shows they really thought about what someone would need when they used this method for the first time.
It could have been "elementType: The element type." if i'd been writing it :-)
Troy.