I have a list of entities which contain some of it fields as other entities.
Eg.
MyEntity
Int id
ContactEntity Contact -> contactId, Name etc…
AddressEntity Address
So I have List< MyEntity>
which needs to be converted to a data table. But from the sub entities I want only one field to be selected.
Is it possible or do I have any other alternative.
UPDATE
When I try CopyToDataTable() as ivowiblo describes it gives me following error
The type 'AnonymousType#1' cannot be used as type parameter 'T' in the generic type or
method 'System.Data.DataTableExtensions.CopyToDataTable<T>(System.Collections.Generic.IEnumerable<T>)'.
There is no implicit reference conversion from 'AnonymousType#1' to 'System.Data.DataRow'.