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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:33:42+00:00 2026-06-05T01:33:42+00:00

Looks a common situation to me: I have two tables: documents: dID (pk, int),

  • 0

Looks a common situation to me: I have two tables:
documents:
dID (pk, int), dName(varchar)

and document_options:
dID (int), oType(int), oValue(varchar)

I would like to have a class Document with a property Options (a List of DocumentOption class)

Since document_options has no PK I cannot use HasMany, and rows from this table don’t seem like ‘real’ entities anyway…

I see a way to generate an auto-number key for document options and map with HasMany, or maybe create a composite ID, but I’d like to know if there is a better option that I don’t know about.

  • 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-06-05T01:33:44+00:00Added an answer on June 5, 2026 at 1:33 am

    In this case, DocumentOptions is a value object, since it has no identity of its own and has no meaning outside of the document it belongs to. So, you would use Component to map the collection properties to the value object.

    public class Document : Entity // don't worry about Entity; it's a base type I created that contains the Id property
    {
        public virtual string Name { get; set; }
    
        public virtual IList<DocumentOptions> Options { get; protected set; }
    
        public Document()
        {
            Options = new List<DocumentOptions>();
        }
    }
    
    public class DocumentOptions
    {
        public virtual int Type { get; set; }
    
        public virtual string Value { get; set; }
    }
    

    And the mapping:

    public DocumentMap()
    {
        Table("documents");
    
        Id(c => c.Id)
            .Column("dId")
            .GeneratedBy.HiLo("10");
    
        Map(c => c.Name)
            .Column("dName");
    
        HasMany(c => c.Options)
            .Component(c =>
                           {
                               c.Map(c2 => c2.Value).Column("oValue");
                               c.Map(c2 => c2.Type).Column("oType");
                           })
            .Table("document_options")
            .KeyColumn("dId")
            .Cascade.AllDeleteOrphan();
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very common situation and a solution, but I would like to
I have what seems to be a pretty common CSS inheritance situation, but I
I have a every common page a.html which looks like this: <html> <head> <script
I have two tables A and B with A referencing a column in B
I'm currently working on two social networking sites that have a lot in common,
Pretty common situation, I'd wager. You have a blog or news site and you
A common piece of code I use for simple string splitting looks like this:
It looks like $smth is not a function is a very common problem with
Looks like operator new and operator new[] have exactly the same signature: void* operator
I have a simple, but probably common problem on how to inject HTML inside

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.