Skip to content

Tortuga Chain 1.1 Release Notes

Jonathan Allen edited this page Apr 12, 2017 · 1 revision

New Features

Master/Detail - Join Appender

For performance reasons, it is often better to have a stored procedure return two records sets, one for the master records and one for the detail records.

This can be annoying because you then have to join them all back together. In order to make this easier, we’ve added the Join appender to our fluid API.

dataSource.Procedure("GetCustomersWithOrders", SearchParameter).ToCollectionSet<Customer, Order>().Join(nameof(Customer.CustomerKey), nameof(Customer.Orders)).Execute(); 

For more details see: https://docevaad.github.io/Chain/MasterDetail.htm

Update Set

A major hole in many ORMs is the lack of support for set-based updates. If you need to flag a bunch of records, the ORM expects you to load each and every one into application memory, only to immediately send it right back. This wastes a lot of time and resources for the database, network, and application.

With the UpdateSet command builder, you can update records using either a SQL expression or an “update object” that provides the values you want. Here’s an example,

dataSource.UpdateSet("Customers", new { GoldClub = true}).WithFilter("TotalOrders > 500").Execute();

As with all update command builders, you can ask the database for the original or newly updated rows. This is especially useful when you want to immediately update a cache or tell the user what actually got changed.

For more information see https://docevaad.github.io/Chain/UpdateSet.htm

Delete with Filter

Another rarely seen feature in ORMs is the ability to perform set-based deletes. In Chain, this is done using the .DeleteWithFilter command builder. As with UpdateSet, you can use a filter expression or filter objct.

https://docevaad.github.io/Chain/DeleteWithFilter.htm

Table-Valued Functions

Table-valued functions are now supported in Class 2 data sources (e.g. SQL Server, PostgreSQL). Since this returns a “table”, it can be futher filtered using where expressions or filter objects.

Scalar Functions

Scalar functions are now supported in Class 2 data sources (e.g. SQL Server, PostgreSQL).

SQL Server Batch Inserts

At first glance, batch inserts look a lot like bulk inserts. They both offer much better performance than simply inserting each row one-by-one. The main difference is that bulk inserts uses a side-channel and batch inserts use normal SQL.

In real terms this means that you can use batch inserts to do things like echo back the newly inserted rows. This is useful when you need the new primary keys or just want to read default and/or calculated columns.

Batch Insert for SQL Server requires that you provide a user-defined table type.

ToXML/ToXDocument materializers

This is used when you are reading just an XML column. It also works with String columns that you want to read as XML.

We’re looking into a JSON materializer. See https://github.com/docevaad/Chain/issues/203

Optional Properties on Filters

Normally filter objects use all of the properties. So if you filter by new {FirstName = "Tom", LastName = null} then it actually look for nulls in the LastName column.

With FromOptions.IgnoreNullProperties, it will skip null properties instead.

Update/Delete by Key

You can now perform updates and deletes using a key, or list of keys.

https://docevaad.github.io/Chain/ByKey.htm

WithRefresh option for CRUD operations

Chain has always had the option to echo back a newly inserted or updated row. Using the WithRefresh materializer, the argument object is updated instead of returning a new object. For example:

DataSource.Insert(EmployeeTableName, emp1).WithRefresh().Execute(); 

This is more appropriate for WPF applications, where the object being saved is data-bound to the UI. With REST services, you don’t really gain anything over calling ToObject.

CollectionSet Materializer

CollectionSet is used when you are getting back multiple result sets from a stored procedure. Each result set can have a different type. For example,

dataSource.Procedure("GetCustomersWithOrders", SearchParameter).ToCollectionSet<Customer, Order>().Execute(); 

Immutable Object Support

Populating immutable objects require calls to a constructor. The constructor to be called can be inferred using the InferConstructor option. Alternately, you can tell it which constructor to use by passing a list of types to the . WithConstructor method.

https://docevaad.github.io/Chain/Object.htm

Immutable Collection Support

ImmutableArray and ImmutableList are now supported.

You’ll generally find that ImmutableArray offers really good performance for both populating the array and reading from it later. For most operations, ImmutableList is the slowest collection type in .NET by several orders of magnitude.

ToDictionary materializer

Objects can be directly materialized into dictionaries. Previously you would have to populate a collection first, then copy it

Bug Fixes

Nested types and compiled materializers

Compiled materializers now support generic and nested types. It even supports generic types nested inside other generic types (which is a lot hard than it should be).

Enums compiled materializers

Enums are now supported by compiled materializers

SQL Server Triggers and Output Clauses

SQL Server has a bug where the Output clause cannot be used to return values if the table being queried has a trigger on it. This fix generates a workaround in SQL so that Chain will continue to work as expected.

https://github.com/docevaad/Chain/issues/170

Thanks go to Michele Liotino for reporting this bug.

Clone this wiki locally