Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6623595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:33:05+00:00 2026-05-25T21:33:05+00:00

POST EDITED – see edit below I have a query about the FLuent Automapping

  • 0

POST EDITED – see edit below

I have a query about the FLuent Automapping which is used as part of the SHarp Architecture. Running one of the tests cases will generate a schema which I can use to create tables in my DB.

I’m developing a site with Posts, and Tags associated with these posts. I want a tag to be able to be associated with more than one post, and for each post to have 0 or more tags.

I wanting to achieve a DB schema of:

Post {Id, Title, SubmitTime, Content}

Tag {Id, Name}

PostTag {PostId, TagId}

Instead, I’m getting:

Post {Id, Title, SubmitTime, Content}

Tag {Id, Name, PostID (FK)}

I’m using sharp architecture, and may classes look as follows (more or less):

public class Post : Entity
{
    [DomainSignature]
    private DateTime _submittime;
    [DomainSignature]
    private String _posttitle;

    private IList<Tag> _taglist;

    private String _content;

    public Post() { }

    public Post(String postTitle)
    {
        _submittime = DateTime.Now;
        _posttitle = postTitle;
        this._taglist = new List<Tag>();
    }


    public virtual DateTime SubmitTime { get { return _submittime; } private set { _submittime = value; } }

    public virtual string PostTitle { get { return _posttitle; } private set { _posttitle = value; } }

    public virtual string Content { get { return _content; } set { _content = value; } }

    public virtual IList<Tag> TagList { get { return _taglist; }  set { _taglist = value; } }




 public class Tag : Entity
{
    [DomainSignature]
    private String _name;

    public Tag() { }

    public Tag(String name)
    {
        this._name = name;
    }

    public virtual String Name
    {
        get { return _name; }
        private set { _name = value; }
    }

    public virtual void EditTagName(String name)
    {
        this.Name = name;
    }

}

I can see why it’s gone for the DB schema set up that it has, as there will be times when an object can only exist as part of another. But a Tag can exist separately.

How would I go about achieving this? I’m quite new to MVC, Nhibernate, and SHarp architecture, etc, so any help would be much appreciated!

EDIT*

OK, I have now adjusted my classes slightly. My issue was that I was expecting the intermediate table to be inferred. Instead, I realise that I have to create it.
So I now have (I’ve simplified the classes a bit for readability’s sake.:

class Post : Entity
{
 [DomainSignature]
 String Title
 [DomainSignature]
 DateTime SubmitTime
 IList<PostTag> tagList

}

class Tag : Entity
{
[DomainSignature]
string name
}

class PostTag : Entity
{
[DomainSignature]
Post post
[DomainSignature]
Tag tag
}

This gives me the schema for the intermediate entity along with the usual Post and Tag tables:

PostTag{id, name, PostId(FK)}

The problem with the above is that it still does not include The foreign key for Tag. Also, should it really have an ID column, as it is a relational table? I would think that it should really be a composite key consisting of the PK from both Post and Tag tables.

I’m sure that by adding to the Tag class

IList<PostTag> postList

I will get another FK added to the PostTag schema, but I don’t want to add the above, as the postList could be huge. I don’t need it every time I bring a post into the system. I would have a separate query to calculate that sort of info.

Can anyone help me solve this last part? Thanks for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:33:05+00:00Added an answer on May 25, 2026 at 9:33 pm

    Ok, I’d been led to believe that modelling the composite class in the domain was the way forward, but I finally come across a bit of automapper override code which creates the composite table without me needing to create the class for it, which was what I was expecting in the first place:

    public class PostMappingOverride
    : IAutoMappingOverride
    {
    public void Override(AutoMapping map)
    {

                map.HasManyToMany(e => e.TagList)
                   .Inverse()
                   .Cascade.SaveUpdate();
            }
        }
    

    This will now give me my schema (following schema non simplified):

    create table Posts (
        Id INT not null,
       PublishTime DATETIME null,
       SubmitTime DATETIME null,
       PostTitle NVARCHAR(255) null,
       Content NVARCHAR(255) null,
       primary key (Id)
    )
    
    create table Posts_Tags (
        PostFk INT not null,
       TagFk INT not null
    )
    
    create table Tags (
        Id INT not null,
       Name NVARCHAR(255) null,
       primary key (Id)
    )
    
    alter table Posts_Tags 
        add constraint FK864F92C27E2C4FCD 
        foreign key (TagFk) 
        references Tags
    
    alter table Posts_Tags 
        add constraint FK864F92C2EC575AE6 
        foreign key (PostFk) 
        references Posts
    

    I think the thrower is that I’ve been looking for a one-to-many relationship, which it is, but it is called HasManytoMAny here…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: I have edited my post... Working on a project (c#), I have a
** post was edited, more info below I've just watched two great videos about
I have edited this post with my question writen in a more simple way
(Note: This post has been edited to show specific use case. See bottom.) I
EDITED: Updated 3/23/09. See rest of post at bottom. I'm still having trouble with
Edited Post These are the new functions that I have created using your template
I've edited this post to better fit the scope of Stackoverflow: I have very
According to my previous Query that post i have a table that looks like
[EDIT] Alright, I edited this post since the code I posted back then had
I have stolen/found/used/written and edited the following widget of jQuery for a auto-completing dropdown.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.