From many to many relationships with ServiceStack.OrmLite

I am checking the ServiceStack documentation, but I have not found a way to do much for many relationships with ServiceStack.OrmLite, is this supported? Is there a workaround (without writing raw sql)?

I would like to have something like this:

Article <- ArticleToTag β†’ Tag

Thanks!!

+6
source share
1 answer

Is it implicitly handled automatically for you backstage if that is what you mean? But since OrmLite is just a thin shell around ADO.NET interfaces, anything is possible.

In OrmLite, by default, each POCO table maps 1: 1 to a table. Therefore, if you want the table layout to create it in the same way as in your database, for example

var article = new Article { ... }; var tag = new Tag { ... }; var articleTag = new ArticleTag { ArticleId = article.Id, TagId = tag.Id }; db.Insert(article, tag, articleTag); 

Although you might want to use the built-in blobbing in OrmLite, where any complex type is simply serialized and stored in a single text field. So you can do something like:

 var article = { new Article { Tags = { "A","B","C" } }; 

Where Tags is just a List<string> , and OrmLite will take care of transparently serializing it into the database field for you.

+11
source

Source: https://habr.com/ru/post/925963/


All Articles