我有一個實體列表,其中包含一些字段作爲其他實體。實體到數據表的列表
例如,
MyEntity
Int id
ContactEntity Contact -> contactId, Name etc…
AddressEntity Address
所以我有List< MyEntity>
需要轉換爲數據表。但是從子實體中我只需要選擇一個字段。
是否有可能或者我有其他的選擇。
UPDATE
當我嘗試CopyToDataTable()作爲ivowiblo描述它給了我下面的錯誤
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'.
是的,我已經看到了** http://msdn.microsoft.com/en-us /library/bb669096.aspx**,問題是我有實體內的子實體,我只需要從這些提取一個字段 –