Custom LINQ to SQL Query with dynamic result
[TestFixture] public class TestDynamicLinq2Sql { [Test] public void TestDynamicLinq() { var ctx = new MyDataContext(" <connection string> "); var result = ctx.ExecuteQuery(" SELECT USER [User], SUSER_SNAME() [SysUser] "); foreach (dynamic row in result) { Console.WriteLine(" {0},{1} ", row.User, row.SysUser); } } [Test] public void TestDynamicRow() { dynamic d = new DynamicRow(); d.FirstName = " Albert "; d[" LastName "] = " Einstein "; Console.WriteLine(d.FirstName); Console.WriteLine(d.LastName); } } public static class LinqExtensions { public static IEnumerable<dynamic> ExecuteQuery( this DataContext ctx, string query) { using (DbCommand cmd = ctx.Connection.CreateCommand()) { cmd.CommandText = query; ctx.Connecti