Petr Babička - 327 - Jan 29, 2014

why OrmLite CRUD operations don’t take Type argument?

FYI here’s an example using an untyped api:

It was only for internal use so it only contains Apis for Save’ and ‘SaveAll’, but I’ll extend them now and make them more usable.

? can you be more specific with an example?

Petr Babička:

object obj = Activator.CreateInstance(type);
BaseClass bc = (BaseClass) obj;

db.Insert(bc); // same UpdateNonDefaults, etc.
// <- Trying insert into BaseClass table instead of table from type

Petr Babička:

And i can’t find Insert method with Type argument.
using ServiceStack.OrmLite;

Well it’s because it’s a generic type argument so it uses the type of the POCO as expected. Also a lot of API’s requires a generic type in order to provide a typed expression and most of the use-cases you’re working directly with the POCO so it’s not ideal to unnecessarily pollute the API with partially equivalent untyped API’s where its possible.

Anyway I do have an API I’m using for untyped access, I’ll see if I can create a test showing it with the example above.

Petr Babička:

It looks like we have same results. But I found limit of this. When we need call Select (or methods with expression) then i don’t know how to put expression into argument (because is typed).

My tests:

That’s what I was saying when when I said: "a lot of API’s requires a generic type in order to provide a typed expression"

Anyway I’ve re-factored the untyped API to be more user-friendly and include more CRUD methods at:

These changes are now on MyGet:

Petr Babička:

Thank you very much :slight_smile: