Search code examples
dictionarydata-structuresmany-to-manyrelationshipazure-service-fabric

Implementation of Many to Many relationship model on lists and dictionaries


I have a class Person and classes City, State, Country. I need to store information that particular person lives in a particular city, state and country. Preferably without using of relationship databases and only using standard dictionaries of statefull services.

It is important to mention that entities City, State and Country should be separated for search and fast computations because they contain some data that is not related to persons.

The thing that makes it so difficult for me is that I have restriction on amount of services: I can't treat them like database tables and create a service like PersonCity to store only identifiers.

Is there any good approaches to implement such relationships in Azure Service Fabric and have efficient search? Maybe with some data duplication.

This question is tagged with azure-service-fabric because I also want to know, if my problem is something that service fabric is not intend to work with or is there standard for service fabric approaches to handle such data relationships.


Solution

  • You could use this (very limited) approach:

    Create a dictionary keyed by object-name and valued by object. Like a dictionary with City objects, keyed by City.Name. Repeat for State and Country and Person.

    Then from Person, you can use the City.Name as 'foreign key' in Person.CityName.

    Using this approach you can find city, state, country by their whole name.

    Downsides:

    • You can't search for extended properties, nor do wildcard searches.
    • No referential integrity.
    • Queries on Person always act on multiple dictionaries.

    (My advice: use a proper database or search platform for this problem)