Closed GoogleCodeExporter closed 8 years ago
I'm guessing you're talking about MoreEnumerable.ToDataTable methods. If so, I
think this will overload the functionality unnecessarily when the desired
effect can be achieved already by projecting the dynamic object to an anonymous
one, with strong-typed and bound members, before calling ToDataTable. For
example:
dynamic pt1 = new ExpandoObject();
pt1.X = 123;
pt1.Y = 456;
dynamic pt2 = new ExpandoObject();
pt2.X = 456;
pt2.Y = 789;
var points =
from pt in new[] { pt1, pt2 }
select new { X = pt.X * 2,
Y = pt.Y * 3 };
points.ToDataTable();
Original comment by azizatif
on 23 Sep 2014 at 10:02
[deleted comment]
Hi thanks for responding so fast.
Your answer will only work if at compile time you knew the fields that would
exist. In the instance I am dealing with I'm generating the object at runtime
by using a method to merge 2 objects Tuple<T1,T2> into a single dynamic/expando
object.
Thanks
Original comment by Yakru...@gmail.com
on 23 Sep 2014 at 10:32
True but if you don't know the properties all you can do at run-time with
IDynamicMetaObjectProvider at runtime is discover the property names and their
values, but cannot know the types of the properties in advance. Without the
types, all columns of such a DataTable would be of type System.Object, which I
think is odd. Moreover, a sequence of dynamics, or just objects for that
matter, don't have to be the same type! As a result, the DataTable cannot be
said to have a uniform schema. MoreEnumerable.ToDataTable like many other
methods in LINQ are designed to work over a sequence of homogenous objects of
some type T. If T is dynamic, that's no different than object and a sequence of
such would have to be assumed to be heterogeneous. Even in LINQ, if you have
IEnumerable, you have to go over Enumerable.Cast<T> before you can benefit from
any of the other standard query operators.
Original comment by azizatif
on 23 Sep 2014 at 11:09
Original issue reported on code.google.com by
Yakru...@gmail.com
on 23 Sep 2014 at 6:18