ServiceStack ORMLite support for views

I read a post here about how ORMLite can read something from SQL and fit it into POCO of the same form. It's great.

On the other hand, how does ORMLite handle these β€œView POCOs” when saving them back to the database? Since they are not tables, they can be views, or they can just be any sql select queries, such as:

var rows = dbCmd.Select<ShipperTypeCount>( "SELECT ShipperTypeId, COUNT(*) AS Total FROM Shippers GROUP BY ShipperTypeId ORDER BY COUNT(*)"); 
+4
source share
1 answer

There is nothing special about the POCOs that you use with OrmLite, they are not tied to or linked to base tables, and there is no hidden magic state that OrmLite caches between calls so that it knows which fields it belongs to.

Each time DB is called, OrmLite simply uses POCO to create the corresponding SELECT, INSERT, UPDATE, or DELETE statements based on the definition of the schema type. INSERT Apis shows some examples of this.

It’s best to think of OrmLite as turning your POCO into an SQL statement, which is. Therefore, an attempt to insert a ShipperTypeCount will attempt to insert an entry into a table named ShipperTypeCount if it does not have the [Alias("UseTableNameInstead")] attribute that will be used instead.

+6
source

Source: https://habr.com/ru/post/1445346/


All Articles