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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:40:08+00:00 2026-05-15T02:40:08+00:00

I have the following entity public class Employee { public virtual int Id {get;set;}

  • 0

I have the following entity

public class Employee
{
   public virtual int Id {get;set;}
   public virtual ISet<Hour> XboxBreakHours{get;set}
   public virtual ISet<Hour> CoffeeBreakHours {get;set}
}

public class Hour
{
   public DateTime Time {get;set;}
}

(What I want to do here is store information that employee A plays Xbox everyday let’s say at 9:00 13:30 and has a coffee break everyday at 7:00 12:30 18:00) – I am not sure if my approach is valid at all here.

The question is how should my (ideally fluent) mappings look like here? It is not necessary (from my point of view) for Hour class to have Id or be accessible from some kind of repository.

  • 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-15T02:40:09+00:00Added an answer on May 15, 2026 at 2:40 am

    Depending on how you want to do it, you either need to map your collection as an element mapping or as a component collection (that’s <element> and <composite-element> in NHibernate terms). The former will need an IUserType defining, while the latter is for if you’re going to have your Hour class have more than one property.

    If you’re sticking with a single property, you’ll need to define an IUserType so NHibernate knows how to translate to and from your type to your database. Once you’ve done that, you can map it with Fluent NHibernate like so:

    HasMany(x => x.XboxBreakHours)
      .Element("value", x => x.CustomType<YourUserType>);
    

    That specifies that your collection is stored in a table with a column called value containing the actual values. The CustomType call is what tells NHibernate to use the IUserType for this collection.

    If you’re going to have multiple properties in your Hour class, then you need to do the following (note: this is actually very similar to doing a Component mapping).

    HasMany(x => x.XboxBreakHours)
      .Component(comp =>
      {
        comp.Map(x => x.Time);
        comp.Map(x => x.Another);
      });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following entity public class Employee { public int EmployeeID { get;
I have the following entity: public class Product{ public int ID { get; set;
I have the following entity: public class User { public int ID {get; set;}
I have the following Post entity: public class Post { public string Id {get;set;}
I have the following model entity: public class ScheduledTask { public virtual int ScheduledTaskId
I have the following entity: public class Alert { public virtual int Id {
I have the following 2 entities: @Entity(name = Employee) @Table(name = EMPLOYEE) public class
I have the following simple entity: public class Something{ [DatabaseGenerated(DatabaseGeneratedOption.Computed)] public int ID {
I have the following Entity model: public class Todo { [Required] public int ID
I have the following JPA (2.0.2) entities: Employee @Entity @Table(name = T_EMPLOYEE) public class

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.