Open Closed

how to implement a many to many relationship #412

cicciottino created

I'd like to set up a tagging system for an entity in order to get a many to many relationship How is it possible achieve this sort relationship in abp?

Using a tag entity, an article entity and between them...? should i create another entity like "artcicles_tags"? Must this middle entity be derived from "Entity<long>" as well? and the mapping configuration is by convention or i must mapping it manually? Could you give me some clues? some suggestion?

2 Answer(s)
  • 0
    ddnils created

    Have a look at Entity Framework.

    You can pretty much use either. If you just want Many to Many relationship, thats possible by just creating your Entities the right way:

    public class Article: Entity&lt;long&gt; {
      public  long Id {get;set;}
      public virtual ICollection&lt;Tag&gt; Tags {get;set;}
    public class Tag: Entity&lt;long&gt; {
      public virtual ICollection&lt;Article&gt; Articles {get;set;}

    This should work. (EF creates your tables)

    But if you want your relationship table to have additional fields (ie. CreationDate) you need to use FluentApi.

    See this document for help: <a class="postlink" href=""> ... first.aspx</a>

  • 0
    cicciottino created

    oh thanks a lot i did it quickly and easily

    1. Added the navigation properties
    2. Add-Migration
    3. Update-Database

    and it's done, nice.