Question

I am having an issue on application start up when I setup my AutoMapper config. It is throwing an exception when creating the mapping for a business object to a data object. The issue appears to be coming from the use of data annotations. It is worth mentioning that the mapping from data object to business object works just fine.

The exception that I get is a CustomAttributeException:

'Order' property specified was not found.

AutoMapper.config Mapping:

           Mapper.CreateMap<Note, NoteData>();

The database object is defined as:

public class NoteData
{
    [Key]
    [Column(Order = -1)]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public virtual Guid Id { get; set; }

    [Timestamp]
    [ConcurrencyCheck]
    [Column(Order = 999)]
    public virtual byte[] Version { get; set; }

    [Required]
    public virtual DateTime Date { get; set; }

    [Required]
    [StringLength(500)]
    public virtual string Value { get; set; }

    public virtual bool IsDeleted { get; set; }

    [Required]
    public virtual UserData CreatedBy { get; set; }
}

I have tried ignoring the fields that have Column Order data annotations on them but that did not resolve the issue.

When I comment out the Order data annotations, Automapper has no issues. So my main question is there a way to configure AutoMapper to work with the Column Order data annotations?

Était-ce utile?

La solution

Order can't be negative one. And since an answer needs at least 30 characters let me add MSDN's doc:

Gets or sets the zero-based order of the column the property is mapped to.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top