Reliable Dictionary of Reliable Dictionaries - azure-service-fabric

Can I have a reliable dictionary which holds another reliable dictionary as its value?
var dicts = await StateManager.GetOrAddAsync<IReliableDictionary<string, IReliableDictionary<string, string>>>("Dictionaries");
My first try gave a serialization error:
Type
'Microsoft.ServiceFabric.Data.Collections.DistributedDictionary`2[System.String,System.String]'
cannot be serialized.
Consider marking it with the DataContractAttribute attribute,
and marking all of its members you want serialized with the DataMemberAttribute attribute.
If the type is a collection, consider marking it with the CollectionDataContractAttribute.
See the Microsoft .NET Framework documentation for other supported types.

Related

I want to store a collection of small non-primitive types using Entity Framework and Cosmos DB

Using Entity Framework and Cosmos DB, I want to store an object that has a property of type HashSet<Guid>. I got an exception message that Guid is not a primitive type and collections of it cannot be mapped. OK, I wrote a pair of ValueConverter/ValueComparer for HashSet<Guid>, but that feels... not very elegant. Is there a better way to do it? I also have a collection of small custom objects that can be stored as a string with a certain syntax. I tried setting a converter/comparer in the ConfigureConventions but it didn't work either. Is it possible to store an ICollection<MySmallType> as a collection of strings? Thank you!

What does Realm Database save? Only variables or functions as well?

In this simple class:
class Simple: Object{
#objc var name: String = ""
func doSomething(){}
}
When I save this into Realm, what does get saved? The variable only or the function as well? The reason I am asking this, is because when I got a lot of Simple objects, I do not want to save the functions ofcourse. The objects would get bigger causing a negative influence on performance.
The variable. It creates a 'column' named "name". Check the realm docs.
Also if you have a lot of data and you would like to browse it you could do it with this Realm Browser where you can see clearly your realm database structure.
You should read through the official documentation and especially the part about supported model properties, which clearly mentions what you can persist in Realm objects.
You can only save properties of certain supported types (Int, String, etc.) or references to other Realm objects (as one-to-to, one-to-many or inverse relations), but you cannot save function references and it wouldn't make sense anyways.
You can add ignored properties and functions to your Realm model classes, but they will only exist in memory, they won't be saved to Realm. For functions this is all you actually need, it wouldn't make any sense to save a function to local storage.
Also, your current model is flawed as your name property is missing the dynamic keyword in its declaration and hence it cannot be treated as a Realm property.

dynamic value class - schema not known until runtime

All the examples for storing multi-field data require specifying a value class. However, I do not know the fields or their types until run-time. I would like to be able to create a region with a dynamic set of field values. For example,
put --key=101 --value=('firstname':'James','lastname':'Gosling')
--region=/region1 --value-class=data.Person
However, the data.Person class does not exist.
Furthermore, I would like to be able to query on the firstname field (or any other field of the value).
How can I do this with Geode?
You don't need a domain class to store data in Geode. You can store json natively in Geode. OQL queries make no distinction between PDX serialized objects and json values. In fact, when you store a json value in Geode, beneath the covers it is converted into a PDXInstance. You can read more about PDX Serialization in the documentation.
You can use PdxInstance.
Example using Java:
region.put(101, cache.createPdxInstanceFactory("data.Person").writeString("firstname","James")
.writeString("lastname","lastname").create());

Inferring type in queries instead of string predicates in Realm Swift?

I'm considering moving from my Core Data wrapper to Realm for my app and one thing that's nagging is how Realm uses strings for their predicates instead of inferring the type in their queries.
For example, why do I have to do this:
Realm().objects(Dog).filter("age < 5").sorted("name")
Instead of the Swift way like this:
Realm().objects(Dog).filter { $0.age < 5 }.sorted { $0.name }
And I missing something, or is this really how you use Realm for Swift?
Using Swift's built-in collection filtering methods is less efficient than using Realm's NSPredicate interface for querying.
A key reason that Swift's built-in collection filtering is less efficient is that it requires allocating a Swift object for each object stored in the Realm. This is necessary as a Swift object must exist in memory for Swift to evaluate expressions such as $0.age < 5. Using NSPredicate allows Realm to translate the predicate into an internal query format that can be evaluated directly against the properties stored in the Realm, without allocating instances of the Swift model classes. The instances can then be lazily allocated as objects in the result set are accessed.
Realm's query execution engine can also perform more optimizations when it understands the semantics of the query being performed. For instance, indexes can be used to more efficiently execute queries when indexed properties are used. If the predicate were a Swift closure its behavior would be opaque to Realm, preventing these optimizations.
It's worth pointing out that NSPredicate is used for queries by Core Data too, for very similar reasons.

Breeze JS Adding a static Lookup dictionary to Metadata

One of my domain models has an Enum property that I like to create a dropdown box for, but the EFContextProvide Metadata function doesn't automatically import the Enum Entity Type for me to access it, so I created a static dictionay of that I like to add to the Metadata Mapping, acting as a lookup table. How can I add Enum entity type, so I can call:
breeze.EntityManager.createEntity(myEnum,...)
right now, I get the following error:
Error: Unable to locate an 'Type' by the name: myEnum
Any suggestion?
UPDATE: (I just added the enumType info of the Metadata function call)
"enumType":{"name":"Plugins","isFlags":"false","underlyingType":"Int32","member":["name":"Custom","value":"0"},{"name":"PluginOfTypeA","value":"1"},{"name":"PluginOfTypeB","value":"2"}]}
Thanks #Jay for your response, I was set in the right direction. Here is what I can say about dealing with Enum:
I created a lookup list on the server that I can separately call, to populate the dropdown list. I have a regular array that I initialize on the success promise of the results, list this data.results[0].myEnumLookup and then on the Viewmodel, I access that property and set in to the ko.observableArray() so I can refer to it in my View. Make sure you set the value: property of the select tag, to the value of item.
But the problem with doing it this way was that at the Save time, it wasn't reading Enum value and it was treating it as just text, so it was failing, so
More robust solution:
In our application we happen to really benefit from having an Enum and their pre-compile value, since we are using those Enum Domain models in other POCO projects, so I ended creating an EF DbSet and proper table that will be populated with all of my Enums values and I can save them into the DB, so now we have the list of items in DB, and I created a single level of inheritance for Enums, so in my controller, I get a IQueryable method that will get all of those Enums, and in the breeze application, in my config file, I define the types of enums, and then I will populate lists of items based on different types in my config, so I can refer to it in my view and binding it to the ko.observableArray(). Also in my original class, I no longer refer to the Enum, I will create MyEnumId as well as virtual MyEnum property that will do the mapping automatically in my EF5 setup.
Lesson I learned, even though Enum in .NET4.5 & EF5 is possible to store and read back, but it's not very practical when it comes to SPA front-end technologies, so I prefer having the integer value, and just manage the enums outside of it.
Not entirely sure I understand the question. By 'Enum entity type' do you mean an 'EntityType' that only has a fixed number of possible instances? If so, you can simply query the entire collection of these entity/instances onto the client and add them directly into your static dictionary. Since, the collection is conceptually immutable, you can query this at the beginning of you session. Further, you should NEVER need to create an instance of any of these 'entity enums' because you can always extract them from your dictionary.
But maybe I'm not understanding your question.