Implementing custom serialization

Our example must read all values from a dataset and then calculate the statistical moment over all values. This is why we must store the list of values in .NET lists. At the moment, native serialization used internally in CLR aggregates fail. This is because .NET lists are too complicated for the simple method of serialization. Consequently, the first adjustment in our source code is to implement the IBinarySerializable interface. Furthermore, the decoration of the SqlUserDefinedAggregate attribute also has to be changed. The following section of the code shows what to do here:

//original code generated by Visual Studio[Serializable][SqlUserDefinedAggregate(Format.Native)]public struct StatMoment//adjustments ...

Get Hands-On Data Science with SQL Server 2017 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.