For years i’ve been under the impression that with the advent of anonymous types in C#, e.g.:
// anon is compiled as an anonymous type
var anon = new { Name = "Terry", Age = 34 };
Linq to Sql is able to construct anonymous typed objects from a results set, e.g.:
Example (hypothetical syntax):
var activeUsers =
from u in ConnectionStrings:Northwind.Users
where u.IsActive = 1
select UserName, FullName, Email, Description
And now i can operate on this collection, e.g.:
foreach (var u in activeUsers)
{
AddToListView(u.UserName, u.FullName, u.Email);
}
Is this simple, powerful, easy to use example a fantasy?
Linq to Sql requires a
DataContextand associated database metadata before it can query a database.It is also not able to “use” a
web.configconnection strings entry (as without static design-time metadata it cannot compile the query.