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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:45:52+00:00 2026-05-30T10:45:52+00:00

I’m using the great .NET library AutoPoco for creating test and Seed Data. In

  • 0

I’m using the great .NET library AutoPoco for creating test and Seed Data.

In my model I have 2 date properties, StartDate and EndDate.

I want the EndDate to be 3 hours after the start Date.

I’ve created a custom Data source for autopoco below that returns a random Datetime between a min and max date

class DefaultRandomDateSource : DatasourceBase<DateTime>
{
    private DateTime _MaxDate { get; set; }
    private DateTime _MinDate { get; set; }
    private Random _random { get; set; }


    public DefaultRandomDateSource(DateTime MaxDate, DateTime MinDate)
    {
        _MaxDate = MaxDate;
        _MinDate = MinDate;

    }

    public override DateTime Next(IGenerationSession session)
    {
        var tspan = _MaxDate - _MinDate;
        var rndSpan = new TimeSpan(0, _random.Next(0, (int) tspan.TotalMinutes), 0);


        return _MinDate + rndSpan;
    }

}

But in AutoPoco’s configuration how can i get my EndDate to be say, 3 hours after the autogenerated start Date?

Here’s the autopoco config

 IGenerationSessionFactory factory = AutoPocoContainer.Configure(x =>
            {
                x.Conventions(c => { c.UseDefaultConventions(); });
                x.AddFromAssemblyContainingType<Meeting>();
                x.Include<Meeting>()
                    .Setup((c => c.CreatedBy)).Use<FirstNameSource>()
                    .Setup(c => c.StartDate).Use<DefaultRandomDateSource>(DateTime.Parse("21/05/2011"), DateTime.Parse("21/05/2012"));
            });
  • 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-30T10:45:53+00:00Added an answer on May 30, 2026 at 10:45 am

    If I am correctly understanding the problem you need: to set EndDate from StartDate. I had to create a new DataSource and get current item which we are constructing and read value from it. I haven’t thoroughly checked but it might fail if StartDate is set after EndDate (though I think the properties are set in the order they are setup, read source code for AutoPoco). Also I am using latest version from CodePlex as of today (20 Feb 2012).

    public class MeetingsGenerator
    {
        public static IList<Meeting> CreateMeeting(int count)
        {
            var factory = AutoPocoContainer.Configure(x =>
            {
                x.Conventions(c => { c.UseDefaultConventions(); });
                x.Include<Meeting>()
                    .Setup((c => c.CreatedBy)).Use<FirstNameSource>()
                    .Setup(c => c.StartDate).Use<DefaultRandomDateSource>
                                      (DateTime.Parse("21/May/2012"), 
                                        DateTime.Parse("21/May/2011"))
                    .Setup(c => c.EndDate).Use<MeetingEndDateSource>(0, 8);
            });
            return factory.CreateSession().List<Meeting>(count).Get();
        }
    }
    
    public class Meeting
    {
        public string CreatedBy { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
    }
    
    public class MeetingEndDateSource : DatasourceBase<DateTime>
    {
        private int mMin;
        private int mMax;
        private Random mRandom = new Random(1337);
    
        public MeetingEndDateSource(int min, int max)
        {
            mMin = min;
            mMax = max;
        }
    
        public override DateTime Next(IGenerationContext context)
        {
            var node = (TypeGenerationContextNode)((context.Node).Parent);
            var item = node.Target) as Meeting;
    
            if (item == null)
                return DateTime.Now;
    
            return item.StartDate.AddHours(mRandom.Next(mMin, mMax + 1));
        }
    }
    
    class DefaultRandomDateSource : DatasourceBase<DateTime>
    {
        private DateTime _MaxDate { get; set; }
        private DateTime _MinDate { get; set; }
        private Random _random = new Random(1337);
    
        public DefaultRandomDateSource(DateTime MaxDate, DateTime MinDate)
        {
            _MaxDate = MaxDate;
            _MinDate = MinDate;
        }
    
        public override DateTime Next(IGenerationContext context)
        {
            var tspan = _MaxDate - _MinDate;
    
            var rndSpan = new TimeSpan(0 
                                      , _random.Next(0, (int)tspan.TotalMinutes)
                                      , 0);
    
            return _MinDate + rndSpan;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.