SoFunction
Updated on 2025-03-08

C# DataTable Convert to Entity Class Object Instance


private static List<T> TableToEntity<T>(DataTable dt) where T : class,new()
{
    Type type = typeof(T);
    List<T> list = new List<T>();

    foreach (DataRow row in )
    {
        PropertyInfo[] pArray = ();
        T entity = new T();
        foreach (PropertyInfo p in pArray)
        {
            if (row[] is Int64)
            {
                (entity, Convert.ToInt32(row[]), null);
                continue;
            }
            (entity, row[], null);
        }
        (entity);
    }
    return list;
}

// Call:

List<User> userList = TableToEntity<User>(YourDataTable);