Skip to main content

Posts

Showing posts from May, 2014

List to ICollection AutoMapper and WebAPI problem

I was getting an exception from Automapper when it tried to map a List to an ICollection . The problem was that WebApi was building the MyClass from the xml sent by the client and instead of using a List for the ICollection property, it used a plain array. When Automapper tried to map the List to the Array, it failed because even though Arrays are ICollections, they do not support some of the ICollection operations, such as Add.  To solve the problem, I used Json in the client side when posting. After that, webapi chose to use List instead of an Array when the data came as Json.

Cryptic message when serializing Computed Observable to JSON

If you have an error in one of your computed observable in Knockout.js, the toJson function will set the value of that property to a cryptic script snipped when serializing it to JSON. For example: var SortField = function (expression) { this .FieldDef = ko.observable( null ); this .SortOrder = ko.observable( "" ); this .ExpressionType = "SortField" ; this .Label = ko.computed( function () { return this . FieldDef () == null ? "" : this . FieldDef ().Label + ' ' + this .SortOrder(); }, this ); } var FieldDefinition = function (table_name, field_name, table_alias) { this .TableName = table_name; this .TableAlias = ko.observable(table_alias); this .FieldName = field_name; this .Label = ko.computed( function () { return this .TableAlias() + '⇨' + field_name; }, this ); In this example SortField’s Label function ...