private void TestForm_Load(object sender, EventArgs e) { var db = new SqlProxyDC(); int id = 1; var orders = db.Orders.Where(o => o.Id == id); var xmlRes = orders.Select( o => new MyClass { OrderId = o.Id, CustomerId = o.CustomerId, CustomerName = o.Customer.Name }); var result = ProxyQuery(db, xmlRes); grid.DataSource = result.ToList(); }
private static IEnumerable <T> ProxyQuery <T>(SqlProxyDC db, IQueryable <T> xmlRes) where T : new() { var type = typeof(T); var prop = type.GetProperties(); var data = ReadData( @"Data Source=(localdb)\ProjectsV12;Initial Catalog=SqlProxyDB;Integrated Security=True;Connect Timeout=30", xmlRes.ToString(), db.GetCommand(xmlRes).Parameters); foreach (var row in data.Rows.OfType <DataRow>()) { var res = new T(); foreach (var propertyInfo in prop) { propertyInfo.SetValue(res, row[propertyInfo.Name]); } yield return(res); } }