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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:17:06+00:00 2026-05-18T08:17:06+00:00

I have a Domain object called User and UserCreateViewModel.Automapper is used for mapping from

  • 0

I have a Domain object called User and UserCreateViewModel.Automapper is used for mapping from ViewModel to User.
Everything is working fine. When mapping is done I see User domain object has values in UserId, CreatedOn and ModifiedOn respectively like

00000000-0000-0000-0000-000000000000
1/1/0001 12:00:00 AM
1/1/0001 12:00:00 AM

These are default values when I instainciate User Object. This cause problem as my User object can not create Guid and Dates from properties Get.

Note: I don’t want to hardcode above default values.

Is there a clean approach to solve this problem so that UserId, CreateOn and ModifedOn generated values from properties?

I you understand my problem

UserCreateViewModel

public class UserCreateViewModel
{
    public string UserName { get; set; }
    public string Password { get; set; }
}

User

private Guid? _guid;
public Guid? UserId
{
    get
    {
        return (_guid.HasValue) ? _guid.Value : Guid.NewGuid();
    }
    set
    {
        _guid = value;
    }
}

public string UserName { get; set; }
public string Password { get; set; }

private DateTime? _createdOn;
public DateTime? CreatedOn
{
    get
    {
        return (_createdOn.HasValue) ? _createdOn.Value : DateTime.Now;
    }
    set
    {
        _createdOn = value;
    }
}

private DateTime? _modifiedOn;
public DateTime? ModifiedOn
{
    get
    {
        return (_modifiedOn.HasValue) ? _modifiedOn.Value : DateTime.Now;
    }
    set
    {
        _modifiedOn = value;
    }
}
  • 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-18T08:17:07+00:00Added an answer on May 18, 2026 at 8:17 am

    Have a look at the BeforeMap and AfterMap features of Automapper. These might help you in customizing the assignment of default values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a domain object called User . Properties of user include ssoId, name,
So let's say we have a domain object such as the following public class
I have a basic domain object, say like Person or Campaign or Event that
I have a property on a domain object that is declared in a many-to-one
I have the current basic structure for each domain object that I need to
Let's say I have an interface representing a domain object: public interface IFoo {
I have the following code in a class that is called from a web
I have the following models. # app/models/domain/domain_object.rb class Domain::DomainObject < ActiveRecord::Base has_many :links_from, :class_name
I have a collection of domain objects that I need to convert into another
We have our domain model declared in rusty old hbm files, we wish to

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.