score:0
i've not tried this, so i can't say for sure that it'll be faster, but it seems to me that you'd get much better speed using something like the following:
dim l_destinationtable as datatable
' this creates a copy of the structure and content
l_destinationtable = sourcetable.copy()
for each l_column as datacolumn in l_destinationtable.columns
dim l_columnmap = omappinginfo.firstordefault( _
function (c) c.sourcefieldname = l_column.columnname )
if l_columnmap isnot nothing then
' rename the column if it is mapped
l_column.columnname = l_columnmap.destinationfieldname
else
' drop the column if it is not mapped
l_destinationtable.columns.remove( l_column )
end if
next
note: this method will fail if an unmapped column is part of a relationship or another column's expression depends on this column. also, if you are swapping the name of two columns (for example, a will be named b and b will be named a) then you will get an exception as two columns may not have the same name at the same time.
Source: stackoverflow.com
Related Query
- How can i copy data table records of different field name based on mapping list evaluating condition on source data table?
- How can I call a Linq-to-Entities (EF4) query specifying a different table name dynamically?
- How can I get data from the Entity Framework if I only know the table name and the column name from which to get the data?
- How do I write a linq to sql query to find records where field name can match one of dynamic number of strings?
- How can I get the total quantity of a sorted field in a data table with lnq?
- How View Model field by another table name based on given ID in LINQ?
- How do I select correct DbSet in DbContext based on table name
- How can I extract a list of Tuple from a specific table with Entity Framework / LINQ?
- How to have a list with different data types of lists in it as a sublists?
- How can I sort a list based on a user's selections in ASP.NET MVC?
- How to retrieve mapping table name for an Entity in Entity-framework in program
- How can I order a List of Dictionary<int, string> based on Dictionary int value?
- How can I get data from a list with a where clause to another list?
- How can I return data from my table grouped but still in order of title?
- How can I create a LINQ-to-SQL statement when I have table name as string?
- How to convert a data table to a list of strongly typed objects in C# using LINQ?
- Linq, selecting two records from one table based on 2 different ID's
- How can I query the contents of a List via LINQ based on string values?
- How to write a generic LINQ query for filtering of data based on first name middle name and last name
- Getting data from a string defined table name filtered on a string defined field
- How can I flatten out data in a list and then get a count of what's in each column using LINQ?
- How to query Link table based data in LINQ
- How can this Data Access Code Lose Data?
- How can I extract data from a list of parent objects with children?
- Using LINQ to XML, how can I join two sets of data based on ordinal position?
- Using Linq to object, how can I get one field's value based on another in the same list
- How to fetch a list from the database based on another list of a different object type?
- How to get unique records of specific columns of data table
- How to create an EF query which returns a nested list with navigation properties based on different entity ids?
- How can I make a list of the element numbers in a list that have a field that is not null?
More Query from same tag
- Lambda Expression: How to map to a List rather than IEnumerable?
- Remove duplicate rows from a list based on selected columns?
- LINQ GroupBy result of previous GroupBy
- LINQ consumes a lot of CPU resources
- Select Max Value in linq to entities
- How to get Sum from List in another List as a property with linq
- How do I properly hook into Json.NET's JObject.ToObject<T>()?
- Applying child collections to matching parents in the parent collection
- using same delegate in LINQ Where(x => f(x) > y) and OrderBy(f) with SQL compilation
- How to use Expression.MakeIndex in Linq Expressions?
- Expression.Property(param, field) is "trolling" me [System.ArgumentException] = {"Instance property 'B.Name' is not defined for type A"}
- .NET CORE 2 EF Include
- Finding items from a list in an array stored in a DB field
- Mapping range variable EF Core to List for automapper
- Fastest way Calculating Sum of Customers' Orders using Linq
- Linq XML to Object, where xml nodes have nested elements
- Efficiency and delayed execution of OrderBy
- Convert linq statement to sql
- Multiple deletions using LINQ (more specifically Linq2Nhibernate, but...)
- LINQ TO SQL, Dynamic query with DATE type fields
- Date conversion operations within linq to entities
- Convert lambda to expression tree
- Convert a parent-child-grandchild hierarchy to another p-c-gc hierarchy
- Does LINQ to SQL support the t-sql "in" statement
- Simple linq question: How to filter a source afterwards?
- convert Dictionary<String, double> to Dictionary<String, float> using Linq
- IEnumerable performs differently on Array vs List
- Check duplicates before update
- How does LINQ Where() clause in .Net work?
- Setting specific values of a list : LINQ