Set a default value to a property

No, there is no built-in way to set the value of a property with metadata. You could use a factory of some sort that would build instances of a class with reflection and then that could set the default values. But in short, you need to use the constructors (or field setters, which are lifted …

Read more

Entity Framework 4.1 InverseProperty Attribute

I add an example for the InversePropertyAttribute. It cannot only be used for relationships in self referencing entities (as in the example linked in Ladislav’s answer) but also in the “normal” case of relationships between different entities: public class Book { public int ID {get; set;} public string Title {get; set;} [InverseProperty(“Books”)] public Author Author …

Read more

C# string interpolation-escaping double quotes and curly braces

It seems that you have missed escape for the products and query objects: $@”{{ “”name””:””{taskName}””, “”products””: [ {{“”product””: “”ndvi_image””, “”actions””: [“”mapbox””, “”processed””]}}, {{“”product””: “”true_color””, “”actions””: [“”mapbox””, “”processed””]}} ], “”recurring””:true, “”query””: {{ “”date_from””: “”{dateFromString}””, “”date_to””: “”{dateToString}””, “”aoi””: {polygon} }}, “”aoi_coverage_percentage””:90 }}”;

Using a class versus struct as a dictionary key

Dictionary<TKey, TValue> uses an IEqualityComparer<TKey> for comparing the keys. If you do not explicitly specify the comparer when you construct the dictionary, it will use EqualityComparer<TKey>.Default. Since neither MyClass nor MyStruct implement IEquatable<T>, the default equality comparer will call Object.Equals and Object.GetHashCode for comparing instances. MyClass is derived from Object, so the implementation will use …

Read more