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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:26:13+00:00 2026-06-13T10:26:13+00:00

I’ve modified a table shown below ALTER TABLE [Plant] ADD Name nvarchar(128) NULL, GLN

  • 0

I’ve modified a table shown below

ALTER TABLE [Plant]
  ADD
    Name nvarchar(128) NULL,
    GLN nvarchar(15) NULL,
    LicenceInformation nvarchar(1024) NULL,
    MondayStart smallint NULL,
    MondayEnd smallint NULL,
    TuesdayStart smallint NULL,
    TuesdayEnd smallint NULL,
    WednesdayStart smallint NULL,
    WednesdayEnd smallint NULL,
    ThursdayStart smallint NULL,
    ThursdayEnd smallint NULL,
    FridayStart smallint NULL,
    FridayEnd smallint NULL,
    SaturdayStart smallint NULL,
    SaturdayEnd smallint NULL,
    SundayStart smallint NULL,
    SundayEnd smallint NULL

Which I’d like to map to something like:

public class Plant : ProjectAggregateRootEntity<int>
{
    public virtual string Code { get; set; }
    public virtual string Name { get; set; }
    public virtual string Gln { get; set; }
    public virtual string LicenceInformation { get; set; }
    public virtual IDictionary<DayOfWeek, PlantOpeningHours> OpeningHours
    {
        get; set;
    }
}

public class PlantOpeningHours
{
    public virtual DayOfWeek Day { get; set; }
    public virtual int StartMinutes { get; set; }
    public virtual int DurationMinutes { get; set; }
}

So I can enumerate the opening hours per day or reference one specifically like: plant.OpeningHours[DayOfWeek.Monday]

So it’s sort of like a component mapping… but not quite.

Cache.ReadWrite().Region("ReferenceData");
Table("Plant");
Map(x => x.Code);
Map(x => x.Name);
Map(x => x.Gln);
Map(x => x.LicenceInformation);
Component(x => x.OpeningHours, x =>
{
    //??
});
  • 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-13T10:26:14+00:00Added an answer on June 13, 2026 at 10:26 am

    You need to create your own UserType for this:

    public class CustomDictionaryType : IUserType
    {
        public CustomDictionaryType()
        {
            SqlTypes = Enumerable.Range(0, 14).Select(x => SqlTypeFactory.Int32).ToArray();
        }
    
        public bool Equals(object x, object y)
        {
            // should do a key/value comparison here
            return ReferenceEquals(x, y);
        }
    
        public int GetHashCode(object x)
        {
            return x.GetHashCode();
        }
    
        public object NullSafeGet(IDataReader rs, string[] names, object owner)
        {
            // DayOfWeek.Sunday = 0, so have to shift days down by one since we start with Monday in our columns
            return names.Select((x, i) => new {DayOfWeek = GetDay(i/2), value = (int) rs[x]})
                .GroupBy(x => x.DayOfWeek, x => x.value)
                .ToDictionary(g => g.Key, g => new PlantOpeningHours
                                                   {
                                                       DayOfWeek = g.Key,
                                                       StartMinutes = g.First(),
                                                       DurationMinutes = g.First() - g.Last()
                                                   });
        }
    
        private DayOfWeek GetDay(int index)
        {
            return (DayOfWeek) ((index + 6)%7);
        }
    
        public void NullSafeSet(IDbCommand cmd, object value, int index)
        {
            var map = value as IDictionary<DayOfWeek, PlantOpeningHours>;
            if (map == null)
                throw new ArgumentException("Cannot handle null dictionary");
            for(var i = 0; i < 7; i++)
            {
                var day = GetDay(i);
                var entry = map[day];
                ((IDataParameter) cmd.Parameters[index + i*2]).Value = entry.StartMinutes;
                ((IDataParameter) cmd.Parameters[index + i*2 + 1]).Value = entry.StartMinutes + entry.DurationMinutes;
            }
        }
    
        public object DeepCopy(object value)
        {
            return new Dictionary<DayOfWeek, PlantOpeningHours>((IDictionary<DayOfWeek, PlantOpeningHours>) value);
        }
    
        public object Replace(object original, object target, object owner)
        {
            return new Dictionary<DayOfWeek, PlantOpeningHours>((IDictionary<DayOfWeek, PlantOpeningHours>)original);
        }
    
        public object Assemble(object cached, object owner)
        {
            return DeepCopy(cached);
        }
    
        public object Disassemble(object value)
        {
            return DeepCopy(value);
        }
    
        public SqlType[] SqlTypes { get; private set; }
        public Type ReturnedType { get { return typeof (IDictionary<DayOfWeek, PlantOpeningHours>); } }
        public bool IsMutable { get { return true; } }
    }
    

    When you map it, you will need to specify the columns in order:

    var propMap = x.Map(t => t.Duration).CustomType<CustomDictionaryType>()
        .Columns.Clear();
    for(var i = 0; i < 7; i++)
    {
        var day = (DayOfWeek) ((i + 6)%7);
        propMap.Columns.Add(day + "Start");
        propMap.Columns.Add(day + "Duration");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a small JavaScript validation script that validates inputs based on Regex. I
For some reason, after submitting a string like this Jack’s Spindle from a text

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.