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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:04:20+00:00 2026-05-16T04:04:20+00:00

I have a SearchService with a Search() method that retrieves an IEnumerable<Search> from a

  • 0

I have a SearchService with a Search() method that retrieves an IEnumerable<Search> from a repository. These Search objects come directly from LINQ To SQL. Next I’m using AutoMapper to convert those Search types into SearchModel types (and later they get passed into a controller, for example).

var searches = searchRepository.GetByUserID(userID);        
var models = Mapper.Map<IEnumerable<Search>, IEnumerable<SearchModel>>(searches);

The problem is that Search has a property DateCreated which is a UTC DateTime. I need to correct the date based on the logged-in user for their local time zone. I could do this with a foreach inside the service, like so:

var searches = searchRepository.GetByUserID(userID);   

foreach (var search in searches)
{
    search.DateCreated = search.DateCreated.ToTimezone(userTimezoneID);
}

var models = Mapper.Map<IEnumerable<Search>, IEnumerable<SearchModel>>(searches);

While this works (and may be the only option), I’d like to make use of AutoMapper’s IValueFormatter. I have a few other value formatters for things like relative time, for example.

My question is: can this be done? I’m unsure because I guess I’d need to pass along additional information to AutoMapper so it knew which time zone ID to use to make the conversion.

I was also trying to avoid getting this from the Search -> User relationship, as I’d have it stored in a cookie when the user logs in (and would like to avoid the database JOIN in retrieving it). How can I pass this time zone ID to AutoMapper so it can do custom mapping per user?

  • 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-16T04:04:21+00:00Added an answer on May 16, 2026 at 4:04 am

    I think you’re going to want to use AutoMapper with a Custom Resolver. Your custom resolve will support dependency injection. It works best if you are using an IoC, but you could inject your user into the resolver and perform appropriate logic within the ResolveCore method. Here’s a rough example:

    private readonly IUserContext _userContext;
    
    public MyResolver(IUserContext userContext)
    {
     _userContext = userContext;
    }
    
    protected override String ResolveCore(object source)
    {                    
     // Calculate display date based on user context
        return TheDate;
    }
    

    Definitely check out the Custom Resolver docs though.

    I hope it helps.

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

Sidebar

Related Questions

Imagine I have a SearchService layer that has a method to search all cars
I have a search form that can search in different provider. I started out
If I have a page that generates search results based on some ajax components
I am following this tutorial to create dynamic search results from an SQL server
I am following this tutorial to create dynamic search results from an SQL server
I have a class that looks like this: class SearchService include Mongoid::Document key :name,
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have converted devise new session from erb to Haml but doens't work, this is
in my asp.net-mvc application I have a statis MvcApplication that calls a static CreateContainer()
I have an input box in html form and onKeyPress of that box I

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.