-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUESTION] Many to Many relation in LiteDB. Is it possible or use other approach? #1638
Comments
@mdmoura I recommend storing each class in its collection and a list of tags as public class Post
{
public ObjectId Id { get; set; }
public String Title { get; set; }
public String Content { get; set; }
[BsonRef("tags")]
public List<Tag> Tags { get; set; }
}
public class Tag
{
public ObjectId Id { get; set; }
public String Name { get; set; }
} This would allow you to efficiently list all posts, list all ags and list all tags in a Post. If you wanted to list all Posts with a specific tag, you could just get the id of the tag you're searching and do something like |
@lbnascimento I tried the following but got really strange results:
When I check And when I check What am I missing? Am I inserting the data incorrectly? |
@lbnascimento I also tried the following:
And this returns an empty list ... I think something might be wrong when using filters with child collections. No? |
@lbnascimento The following query returns the one post, as expected, that contaoins a Tag with slug book:
The following return all record like it wasn't filtered.
Any idea why? |
@mdmoura Have you tried the below? var c = lessons.Include(x => x.Topics)
.Find("Topics[*].Slug ANY = @0", "book")
.ToList(); |
@mdmoura Regarding Regarding Using |
Using LiteDB I have the following Pocos:
Each Post can have many Tags and each Tag can be used in many Posts.
Is it possible to create a Many to Many relation in LiteDB?
My idea would be create a new POCO named PostTag:
And then update the Post and Tag Pocos to the following:
I am not sure if this makes sense. Should I simply use the following?
And what if I need all Tags used in posts?
I would get all tags in all posts and create a list with unique names?
The text was updated successfully, but these errors were encountered: