AutoMapper异常

时间:2012-06-22 17:45:40

标签: automapper

这是我第一次被autpper陷入困境。我试图将存储过程返回的结果集映射到我的实体。 L2S具有可用的结果集,对于我当前的测试,它是一行,可以是多个。如果没有正确处理返回类型可以为空,通常会抛出自动化异常。我已按原样离开它并将其更改为某个值,但在这两种情况下我仍然得到例外。我错过了一些非常基本的东西,但不能把它放在手上。需要第二双眼睛......谢谢。

代码电话

var annualReportOutreachEditionResult = ClientsContext.AnnualReportOutreachEditionInfoGet(fice, reportYear).ToList();
            if (annualReportOutreachEditionResult != null)
            {
                annualReportOutreachEditionDetail = Mapper.Map<List<AnnualReportOutreachEditionInfoGetResult>, List<AnnualReportOutreachEditionDetail>>(annualReportOutreachEditionResult);

AnnualReportOutreachEditionDetail Entity

public class AnnualReportOutreachEditionDetail
    {



        public string Edition { get; set; }


        public DateTime MailDate { get; set; }


        public string CardId { get; set; }


    }

AnnualReportOutreachEditionInfoGetResult L2S实体

public partial class AnnualReportOutreachEditionInfoGetResult
    {

        private string _Edition;

        private System.Nullable<System.DateTime> _MailDate;

        private string _CardId;

        public AnnualReportOutreachEditionInfoGetResult()
        {
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Edition", DbType="VarChar(50)")]
        public string Edition
        {
            get
            {
                return this._Edition;
            }
            set
            {
                if ((this._Edition != value))
                {
                    this._Edition = value;
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_MailDate", DbType="Date")]
        public System.Nullable<System.DateTime> MailDate
        {
            get
            {
                return this._MailDate;
            }
            set
            {
                if ((this._MailDate != value))
                {
                    this._MailDate = value;
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_CardId", DbType="Char(9)")]
        public string CardId
        {
            get
            {
                return this._CardId;
            }
            set
            {
                if ((this._CardId != value))
                {
                    this._CardId = value;
                }
            }
        }
    }

映射

我还检查/测试了defaultvalue的日期,我的异常仍在那里。这是唯一可以为空的类型。

 public static void MapAnnualReportOutreachEditionDetail()
        {
            Mapper.CreateMap<AnnualReportOutreachEditionInfoGetResult, AnnualReportOutreachEditionDetail>()

                ;
        }

例外详细信息

AutoMapper.AutoMapperMappingException was unhandled by user code
  Message=Trying to map System.Collections.Generic.List`1[[Nrccua.LinqToSql.AnnualReportOutreachEditionInfoGetResult, Nrccua.LinqToSql, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] to System.Collections.Generic.List`1[[Nrccua.BusinessEntities.AnnualReportOutreachEditionDetail, Nrccua.BusinessEntities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].
Exception of type 'AutoMapper.AutoMapperMappingException' was thrown.
  Source=AutoMapper
  StackTrace:
       at AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context)
       at AutoMapper.MappingEngine.Map(Object source, Type sourceType, Type destinationType)
       at AutoMapper.MappingEngine.Map[TSource,TDestination](TSource source)
       at AutoMapper.Mapper.Map[TSource,TDestination](TSource source)
       at Nrccua.LinqToSql.DataAccess.AnnualReportAccess.GetAnnualReportOutreachEditionDetails(String fice, String reportYear) in C:\Users\tahir\Documents\DATA\Projects\NrccuaWebSite\NrccuaWebSiteTahirj\Core\BusinessEntities\Nrccua.LinqToSql\DataAccess\AnnualReportAccess.cs:line 211
       at Nrccua.Repositories.AnnualReportRepository.GetAnnualReportOutreachEditionDetails(String fice, String reportYear) in C:\Users\tahir\Documents\DATA\Projects\NrccuaWebSite\NrccuaWebSiteTahirj\Core\Repositories\Nrccua.Repositories\AnnualReportRepository.cs:line 199
       at RepositoryTests.AnnualReportTest.GetOutreachDetailsTest() in C:\Users\tahir\Documents\DATA\Projects\NrccuaWebSite\NrccuaWebSiteTahirj\Core\Tests\RepositoryTests\AnnualReportTest.cs:line 55
  InnerException: AutoMapper.AutoMapperMappingException
       Message=Trying to map Nrccua.LinqToSql.AnnualReportOutreachEditionInfoGetResult to Nrccua.BusinessEntities.AnnualReportOutreachEditionDetail.
Exception of type 'AutoMapper.AutoMapperMappingException' was thrown.
       Source=AutoMapper
       StackTrace:
            at AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context)
            at AutoMapper.Mappers.EnumerableMapperBase`1.Map(ResolutionContext context, IMappingEngineRunner mapper)
            at AutoMapper.Mappers.CollectionMapper.Map(ResolutionContext context, IMappingEngineRunner mapper)
            at AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context)
       InnerException: AutoMapper.AutoMapperMappingException
            Message=Trying to map Nrccua.LinqToSql.AnnualReportOutreachEditionInfoGetResult to Nrccua.BusinessEntities.AnnualReportOutreachEditionDetail.
Missing type map configuration or unsupported mapping.
Exception of type 'AutoMapper.AutoMapperMappingException' was thrown.
            Source=AutoMapper
            StackTrace:
                 at AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context)
            InnerException: 

1 个答案:

答案 0 :(得分:0)

这是我的问题,我忘了添加mapper方法的定义。固定的。