asp.net 2.0
llblgenpro 2
VS 2005
SQL SERVER 2005
Hi,
I've tried to create a function that populate a list of Class Entity from DataTable using .NET reflection but i've got this error:
SD.LLBLGen.Pro.ORMSupportClasses.ORMFieldIsReadonlyException: The field 'ProductID' is read-only and can't be changed
Here is a peice of my code:
public static List<T> FillCollection(System.Data.DataTable dtSource)
{
List<T> retCollection = new List<T>();
foreach (System.Data.DataRow row in dtSource.Rows)
{
object element = Activator.CreateInstance<T>();
element = SetItem((T)element, row);
retCollection.Add((T)element);
}
return retCollection;
}
private static object SetItem(T item, System.Data.DataRow row)
{
Type type = item.GetType();
foreach (DataColumn column in row.Table.Columns)
{
PropertyInfo property = type.GetProperty(column.ColumnName);
if (property != null && property.CanWrite)
{
object value = row[column.ColumnName];
property.SetValue(item, value, null);
}
}
return item;
}
SetItem throw an exception on property ProductID the PK of the table that i want to map in the list.
Any suggestion??
Thanks in advance