Search code examples
mysqlservicestackormlite-servicestack

ServiceStack.OrmLite: Inserting or updating columns that are not represented in the POCO?


I looked through the docs and I didn't find anything on this subject, but I thought I'd ask, to be sure:

Is there a way for OrmLites INSERT and UPDATE APIs to make it possible in one query, to insert/update columns that are not present in the POCO?

DateTime myTimestamp = DateTime.Now;
db.Insert<MyPoco>(myPoco, new { MyNewColumn=myTimeStamp });

or something like it?

I know that I can make a custom SQL, so either make a second query, inserting the custom columns, or write the whole thing myself, but I'd like to avoid that and let OrmLite do what it's supposed to do.


Solution

  • OrmLite is a typed code-first ORM where each POCO is the authoritative source which maps 1:1 to their respective RDBMS tables.

    You can’t use OrmLite’s typed APIs with an unknown or dynamic schema and would need to Execute Custom SQL INSERT, e:g:

    db.ExecuteSql(
        "INSERT INTO page_stats (ref_id, fav_count) VALUES (@refId, @favCount)", 
         new { refId, favCount });