Fetch DataTable without a strongly typed entity

Posts   
 
    
egutierrez
User
Posts: 7
Joined: 12-Nov-2018
# Posted on: 16-Mar-2019 23:12:25   

SD.LLBLGen.Pro.ORMSupportClasses: 4.2.20160929 SD.LLBLGen.Pro.DQE.SqlServer: 4.2.20160929 .NET Framework 4.6.1 Sql Server 12.0.5207.0 (2012)

Hi,

I need to get some DataTables for some tables, but the thing is that I can't use the strongly typed entities or fields to do the query.

For example, if I know the entity is called CustomerEntity and the table is called Customer with some fields like Id, Name, and so on.

So, I would need to query something like SELECT Id, Name FROM Customer and get a DataTable.

I can't use the CustomerEntity or the fields in the code because this is a dynamic feature of the application so I know the names because they are in a configuration repository.

Something like:

var entityName = "CustomerEntity";
var fieldsToQuery = new string[] {"Id", "Name"};

var dataTable = SomeMethodToGetDataTable(entityName, fieldsToQuery);

I know there is FetchAsDataTable() extension method but I don't know how to create a DynamicQuery without using strongly typed entities and fields. I need to create the query only with names as a string.

I understand this is not a normal use of the library and tried to simplify the example but this is something it is required by the application.

Thanks.

DvK
User
Posts: 318
Joined: 22-Mar-2006
# Posted on: 17-Mar-2019 16:10:36   

You can fetch a datatable with only the fields you want by using a ResultSetFields object. Use this object to define an array of EntityField, and then fetch by the FetchTypedList method of Adapter.

http://llblgen.com/Documentation/5.5/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/Adapter/Using%20TypedViews,%20TypedLists%20and%20Dynamic%20Lists/gencode_usingdynamiclists_adapter.htm