How to load any entity from data row or EntityCollection from DataTable

Posts   
 
    
JamesLi
User
Posts: 5
Joined: 26-Aug-2010
# Posted on: 27-Jul-2012 04:23:44   

Adapter , LLBL Gen 3.1 I write an sql query and get the result as the DataTable from SQL Server I want to change dataTable to EntityCollection, just like the following code T is the generic parameter, such as CustomerEntity,RegionEntity.

EntityCollection<T> entities = new EntityCollection<T>(); foreach (DataRow row in table.Rows) { T newCustomer = (T)entities.AddNew(); foreach (DataColumn column in table.Columns) { newCustomer.SetNewFieldValue(column.ColumnName, row[column]); } } }

somtimes it works, but it has bug. such as Table Log(LogID) it will generate mapping field Logid, LogEntity.

so, the SetNewFieldValue won't work, because can not find the LogID property(the generated property name is Logid) .

found a method here http://stackoverflow.com/questions/6191462/llblgen-load-a-entitycollection-or-list-from-a-datatable

but I want it more common,so, I want to know, is there any a way to implementation this?

or ,can you give me the mapping rule, how to get the generated property name by its data column name? for this example, data column is LogID, the generated property name is Logid how the designer do this, thank you

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 27-Jul-2012 07:18:55   

JamesLi wrote:

Adapter , LLBL Gen 3.1 I write an sql query and get the result as the DataTable from SQL Server I want to change dataTable to EntityCollection, just like the following code T is the generic parameter, such as CustomerEntity,RegionEntity.

Why you didn't fetch that data using LLBLGen Pro framework? LLBLGen can fetch some Stored Procedue call, TypedView, or even a RetrievalQuery, and the projecting that into a EntityCollection. See Fetching Datareaders and projections.

JamesLi wrote:

somtimes it works, but it has bug. such as Table Log(LogID) it will generate mapping field Logid, LogEntity.

so, the SetNewFieldValue won't work, because can not find the LogID property(the generated property name is Logid) .

found a method here http://stackoverflow.com/questions/6191462/llblgen-load-a-entitycollection-or-list-from-a-datatable

but I want it more common,so, I want to know, is there any a way to implementation this?

or ,can you give me the mapping rule, how to get the generated property name by its data column name? for this example, data column is LogID, the generated property name is Logid how the designer do this, thank you

LLBLGen uses PascalCasing but there are other rules for naming. It also could happen that the field name is totally different from the table column, since a user can change the name at LLBLGgen Designer. So that approach is no reliable.

David Elizondo | LLBLGen Support Team