Homam
Homam

Reputation: 23861

What's the best type to store a tabular data structure?

I'm developing an integration service provides for some web applications some functionality and services.

One of these service is executing custom queries on a specific database.

There are these methods: (ExecuteScaler, ExecuteNonQuery, ExecuteTable).

I've already implement the first two. Now, what's your suggestion for the return type of ExecuteTable ?

I need a simple data structure demonstrate a table. I've thought of DataTable, Do you have any other suggestion ?

Any suggestion will be appreciated.

Thanks in advance.

Upvotes: 2

Views: 318

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1063338

If the tabular data is arbitrary, and needs to be handled in-memory, then you might as well choose DataTable - it will save you a lot of bug-hunting.

If the data doesn't need to be buffered in memory, I'd use IDataReader and let the consumer pull the data down themselves.

I should stress that DataTable is never my first choice of API, but it may be pragmatic here.

One other option is a generic method ExecuteQuery<T>(..) that fills the data into T instances, perhaps usig something like dapper-dot-net.

Upvotes: 4

Related Questions