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 6237293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:00:06+00:00 2026-05-24T11:00:06+00:00

CREATE TABLE IF NOT EXISTS `movie` ( `m_ID` varchar(9) NOT NULL `ReleaseDate` date `Title`

  • 0
CREATE TABLE IF NOT EXISTS `movie` (
  `m_ID` varchar(9) NOT NULL
  `ReleaseDate` date 
  `Title` varchar(255) NOT NULL 
  PRIMARY KEY (`m_ID`),
  KEY `m_ID` (`ReleaseDate`,`Title`,)
)
CREATE TABLE IF NOT EXISTS `m_director` (
  `dirID` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `dirName` varchar(40) NOT NULL,
  PRIMARY KEY (`dirID`),
  UNIQUE KEY `dirName` (`dirName`)
) 
CREATE TABLE IF NOT EXISTS `m_directs` (
  `m_ID` char(9) NOT NULL
  `dirID` int(11) unsigned NOT NULL,
  UNIQUE KEY `m_ID_2` (`m_ID`,`dirID`),
  KEY `m_ID` (`m_ID`),
  KEY `dirID` (`dirID`)
) 

Also note that m_ID is set as a foreign key to movie table and dirID is set as a foreign key to m_director.

I do not understand how this would get mapped to an object like this one via mapping xmls.

public class Movie
{
public string MovieTitle{get;set;}
public IList<string> Directors;
public DateTime ReleaseDate;
}

I can see it would be fairly easy with a list tag if there was not an intermediary table between movie and m_director(eg m_directs), but for a schema like I have, I do not understand how this is done.

  • 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-24T11:00:08+00:00Added an answer on May 24, 2026 at 11:00 am

    AFAIK public IList<string> Directors; cant be a manytomany because string has no object identity so it cant be linked from different Movies. Therefor you cant map it with NHibernate as manytomany. best way would be to

    public class Movie
    {
        public virtual string Title { get; set; }
        public virtual ICollection<Director> Directors { get; set; }
        public virtual DateTime ReleaseDate { get; set; }
    
        public virtual IEnumerable<string> Directornames
        { get { return Directors.Select(dir => dir.Name); } }
    }
    
    public class Director
    {
        public virtual int Id {get; protected set;}
        public virtual string Name {get; set;}
    }
    
      <class name="Movie" table="movie">
        <id name="Id" column="m_ID"/>
        <property name="ReleaseDate"/>
        <property name="Title"/>
        <bag name="Directors" table="m_directs">
          <key column="m_ID" not-null="true"/>
          <many-to-many class="Director" column="dirID"/>
        </bag>
      </class>
    
      <class name="Director" table="m_director">
        <id name="Id" column="dirID"/>
        <property name="Name" column="dirName"/>
      </class>
    

    then it would be also possible to give directors more information like Birthdate and so on.

    Edited: corrected typos and indentation of xml mapping (hence not shown) and added fluent mapping

    class MovieMap : ClassMap<Movie>
    {
        public MovieMap()
        {
            Table("movie");
    
            Id(m => m.Id, "m_Id").GeneratedBy.Identity();
    
            Map(m => m.Title);
            Map(m => m.ReleaseDate);
    
            HasManyToMany(m => m.Directors)
                .Table("m_directs")
                .ParentKeyColumn("m_ID")
                .ChildKeyColumn("dirID")
                .AsBag()
                .Cascade.All();
        }
    }
    
    class DirectorMap : ClassMap<Director>
    {
        public DirectorMap()
        {
            Table("m_director");
    
            Id(d => d.Id, "dirID").GeneratedBy.Identity();
    
            Map(d => d.Name, "dirName");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

CREATE TABLE IF NOT EXISTS fw_users (id INT(64) NOT NULL PRIMARY KEY AUTOINCREMENT, auth
Using the command: CREATE TABLE IF NOT EXISTS `test`.`t1` ( `col` VARCHAR(16) NOT NULL
create table snippet( id int not null auto_increment, primary key(id), idlanguage int not null,
create table ImagenesUsuario { idImagen int primary key not null IDENTITY } This doesn't
Create Table: CREATE TABLE `category` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255)
CREATE TABLE IF NOT EXISTS `users` ( `id` int(11) NOT NULL auto_increment, `username` varchar(50)
CREATE TABLE IF NOT EXISTS `Channels` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(30)
CREATE TABLE IF NOT EXISTS `MyTable` ( `ID` SMALLINT NOT NULL AUTO_INCREMENT, `Name` VARCHAR(50)
SQL: CREATE TABLE IF NOT EXISTS `photoalbums` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title`
Simplified Table structure: CREATE TABLE IF NOT EXISTS `hpa` ( `id` bigint(15) NOT NULL

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.