views:

69

answers:

1

Hello, Im using LINQ over DataSet but just to get data from some tables, by the way Im interesting on Fill those DataTables using LINQ2SQL cause I recently discover that on some clients with less than 1GB of RAM, the machine memory is Lacking and freeze 1 or 2 seconds and there it go normal, well whatever is frustrating for the client.

... so How to use LINQ2SQL for fill DataTables instead using TableAdapters ?

Thanks

+1  A: 

In this sample I build a datatable and I have a list of name objects that was queried from SQL using Linq to SQL. Loop through the List of name objects building an object array from each of the fields. Then add that array to the datatable. If memory is an issue, I would avoid using a datatable altogether. That datatable will generally use more memory than a generic list.

    public void LoadStandardizedNames(List<StandardName> names)
    {
        using (DataTable table = CreateNamesTable())
        {
            names.ForEach(name => table.LoadDataRow(new object[]
            {
                name.BatchId,
                name.FirstName,
                name.MiddleName,
                name.LastName,
                name.NameSuffix,
                name.Gender,
                name.ChangeCode,
            }, true));
        }   
    }
TGnat
Thanks, this was I looking for stop using TableAdapters
Angel Escobedo