dbpprt / mobiledb

You like EntityFramework and use it frequently but sometimes you need just a simple embedded database for an app or a small application, then MobileDB ist just right for you. It's a lightweight, fast and simple JSON database with an EntityFramework inspired API.
MIT License
18 stars 4 forks source link

Relationship Question #9

Open mxmissile opened 9 years ago

mxmissile commented 9 years ago

Not really an "Issue" but more of a question.

Given Teams and Athletes, Athletes being members of Teams. How would you model this using mobiledb?

Say the Team entity has an Athletes property (Team.Athletes). And I wanted to see a list of all athletes regardless of the team. How would generate that query?

Same goes for reverse, say I have a list of Athletes, but needed to display the parent Team's name in the list. How do you query this without looping through all the athletes and querying the team for each athlete?

dbpprt commented 9 years ago

mobiledb isnt able to detect this Kind of relationship at the Moment. but nevertheless you are able to model this relationship yourself.

Think about the following data Schema:

public class Team {
  [Identity]
  public Guid Id { get; set; }

  public string Name { get; set; }
}

public class Athlete {
  [Identity]
  public Guid Id { get; set; }

  public Guid TeamId { get; set; }

  public string GivenName { get; set; }

  public string SurName { get; set; }
}

With this model you're able to query all the examples above.

mxmissile commented 9 years ago

And then use LINQ for joining. Total brain fart yesterday. Need to get out of the navigational properties mode that NHibernate gives you. Thanks @flumbee