public interface IEntity {
int Id { get; set; }
}
public interface IDatedEntity : IEntity {
DateTime DateCreated { get; set; }
DateTime DateModified { get; set; }
}
public interface IBMSEntity : IDatedEntity {
string Notes { get; set; }
bool Active { get; set; }
}
public class ProjectStatus : IBMSEntity {
public string Name { get; set; }
public StatusType Type { get; set; }
public bool IsDefault { get; set; }
#region Interface Properties
public int Id { get; set; }
public DateTime DateCreated { get; set; }
public DateTime DateModified { get; set; }
public string Notes { get; set; }
public bool Active { get; set; }
#endregion
}
public class BaseDatedEntityUpdate<T> : BaseEntityUpdate<T>, IUpdate<T> where T : class, IDatedEntity {
public BaseDatedEntityUpdate(BMSContext context, IValidationDictionary validation) : base(context, validation) { }
public override T Update(T entity) {
//setting - I'd like to put this on the base mappings also
var now = DateTime.Now;
entity.DateModified = now;
//mapping
var original = dbSet.Find(entity.Id);
Mapper.Map(entity, original);
return original;
}
}
//testing base/interface maps
Mapper.CreateMap<IDatedEntity, IDatedEntity>()
.ForMember(x => x.DateCreated, y=> {
y.UseDestinationValue();
y.Ignore();
});
Mapper.CreateMap<ProjectStatus, ProjectStatus>();
Mapper.Map(entity, original);
Mapper.Map<IDatedEntity, IDatedEntity>(entity, original);
//testing base/interface maps
Mapper.CreateMap<IDatedEntity, IDatedEntity>();
Mapper.CreateMap<ProjectStatus, ProjectStatus>()
.ForMember(x => x.DateCreated, y=> {
y.UseDestinationValue();
y.Ignore();
});
--
You received this message because you are subscribed to the Google Groups "AutoMapper-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to automapper-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Sorry, I misunderstood.
On Nov 30, 2015, at 10:12 AM, Shaun Smith <shauns...@googlemail.com> wrote:
Sorry, I misunderstood.Option 1 shows the ignore map on the interface, this has the problem whereby the properties on ProjectStatus do not map across.
I’m sorry I don’t fully understand,
Are you able to show me an example or pseudo code example?
--
You received this message because you are subscribed to a topic in the Google Groups "AutoMapper-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/automapper-users/TZE4JlhYVas/unsubscribe.
To unsubscribe from this group and all its topics, send an email to automapper-use...@googlegroups.com.
Sorry Jimmy, that was ridiculously simpler than I was expecting.
As you can see from my code I have to use the destination value and I also wish to use other values such as mapping DateTime.Now to DateModified. Is there a way I can achieve this behaviour?
Ok I think I have enough info to give this another attempt.
Thank you so much for all your help Jimmy, I really appreciate it.
p.s. If you drop this info on the StackOverflow I’ve linked at the bottom of the original article, I’ll hand you my 100 bounty points also J