オートマッパーによってこのように動けなくなったのはこれが初めてです。ストアド プロシージャから返された結果セットをエンティティにマップしようとしています。L2S には利用可能な結果セットがあります。現在のテストでは 1 行で、複数行可能です。通常、automaper 例外は、適切に処理されない場合、戻り値の型が null 許容である場合にスローされます。私はそれをそのままにして、いくつかの値に変更しましたが、どちらの場合もまだ例外が発生しています。ここで非常に基本的なことがいくつか欠けていますが、それを手に入れることはできません。2 番目の目が必要です... ありがとう。
コードコール
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;
}
}
}
}
マッピング
日付のデフォルト値もチェック/テストしましたが、例外がまだ残っています。それが唯一の null 許容型です。
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: