I've created an issue over at AutoMapper.
[https://github.com/AutoMapper/AutoMapper/issues/1683])
Okay my initial console code was incorrect, it should be :
class Program
{
static void Main(string[] args)
{
Mapper.Initialize(cfg => cfg.CreateMap<OutgoingTransaction, OutgoingTransactionDto>());
var transaction = new OutgoingTransaction();
var dto = Mapper.Map<OutgoingTransactionDto>(transaction);
}
}
Using automapper 5.1.1 it gives me the error but if I use version 5.0.2 or less then it works...
So the issue is automapper
Hi,
After upgrading ABP to version 0.12.0 I get an exception:
Error mapping types.
Mapping types: OutgoingTransaction -> OutgoingTransactionDto MyTestProject.Transactions.OutgoingTransaction -> MyTestProject.OutgoingTransactions.Dto.OutgoingTransactionDto
Type Map configuration: OutgoingTransaction -> OutgoingTransactionDto MyTestProject.Transactions.OutgoingTransaction -> MyTestProject.OutgoingTransactions.Dto.OutgoingTransactionDto
Property: TruckHaulierName
I have the following models that I've stripped down:
[Table("twtcOutgoingTransactions")]
public class OutgoingTransaction : FullAuditedEntity
{
public DateTime TransactionDate { get; set; }
public int TruckId { get; set; }
public virtual Truck Truck { get; set; }
public OutgoingTransaction()
{
TransactionDate = DateTime.Now;
}
}
[Table("twtcTrucks")]
public class Truck : FullAuditedEntity, IPassivable
{
public string RegistrationNumber { get; set; }
public int HaulierId { get; set; }
[ForeignKey("HaulierId")]
public virtual Haulier Haulier { get; set; }
public bool IsActive { get; set; }
public Truck()
{
IsActive = true;
}
}
[Table("twtcHauliers")]
public class Haulier : FullAuditedEntity, IPassivable
{
//Code
public string Name { get; set; }
public string Description { get; set; }
public bool IsInternal { get; set; }
public bool IsActive { get; set; }
public Haulier()
{
IsActive = true;
}
}
Here is my dto:
[AutoMap(typeof(OutgoingTransaction))]
public class OutgoingTransactionDto : EntityDto
{
public DateTime TransactionDate { get; set; }
public int TruckHaulierId { get; set; }
public int TruckId { get; set; }
public string TruckHaulierName { get; set; }
public string TruckRegistrationNumber { get; set; }
public OutgoingTransactionDto()
{
TransactionDate = DateTime.Now;
}
}
And here is my application service method that I've also stripped down (Error on - var dto = transaction.MapTo<OutgoingTransactionDto>();):
public OutgoingTransactionDto GetTransactionForEdit(int? id)
{
//var transaction = !id.HasValue ? new OutgoingTransaction() : _outgoingTransactionRepository.Get(id.Value);
var transaction = new OutgoingTransaction();
//transaction.Truck = new Truck {RegistrationNumber = "Blah"/*, Haulier = new Haulier {Name = "Cool"}*/ };
var dto = transaction.MapTo<OutgoingTransactionDto>(); //error on this line
return dto;
}
I've also created an empty console application with just auto mapper and it works:
class Program
{
static void Main(string[] args)
{
Mapper.Initialize(cfg => cfg.CreateMap<OutgoingTransaction, OutgoingTransactionDto>());
var transaction = new OutgoingTransaction();
var dto = Mapper.Map<OutgoingTransaction>(transaction);
}
}
What am I missing?
Any help would be appreciated. :-)
Regards, Amir Venter
Hi,
I need to log all changes made to my models. I came across a library called FrameLog (<a class="postlink" href="https://bitbucket.org/MartinEden/framelog/wiki/Home">https://bitbucket.org/MartinEden/framelog/wiki/Home</a>) which does exactly what I need but I'm not sure how to plug it in.
It requires that I make the following changes to my DbContext:
public void Save(User author)
{
Logger.SaveChanges(author);
}
[Obsolete]
public override int SaveChanges()
{
return base.SaveChanges();
}
This won't work because boiler plate takes care of saving changes.
How can I hook into the SaveChanges method so that it can call Logger.SaveChanges(author);.
PS: Thanks for an awesome framework.
Regards, Amir