-1
這是我第一次陷入這樣由automapper。我試圖將存儲過程返回的結果集映射到我的實體。 L2S的結果集可用,它是我當前測試的一行,可以是多個。如果處理不當,返回類型爲空時通常會引發automaper異常。我已經離開了它,也改變了一些價值,但在這兩種情況下,我仍然得到例外。我錯過了一些非常基本的東西,但不能把它放在手上。需要第二雙眼睛......謝謝。AutoMapper異常
代碼調用
var annualReportOutreachEditionResult = ClientsContext.AnnualReportOutreachEditionInfoGet(fice, reportYear).ToList();
if (annualReportOutreachEditionResult != null)
{
annualReportOutreachEditionDetail = Mapper.Map<List<AnnualReportOutreachEditionInfoGetResult>, List<AnnualReportOutreachEditionDetail>>(annualReportOutreachEditionResult);
AnnualReportOutreachEditionDetail實體
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: