シンプルな MVC4 アプリケーションを作成しています
私はオートマッパーを持っています
Mapper.CreateMap<SourceClass, DestinationClass>()
.ForMember(dest => dest.IntphoneNo,
opt => opt.MapFrom(src => src.Stringphoneno));
IntphoneNoは DataType intです (IntphoneNo は私のクラスの変数ですPerson
) ソース属性Stringphonenoは Datatype stringです。
マッピングすると、次のエラーが発生します。
タイプ 'AutoMapper.AutoMapperMappingException' の例外が AutoMapper.dll で発生しましたが、ユーザー コードで処理されませんでした
しかし、IntphoneNo のDatatype をintからstringに変更する と、プログラムは正常に実行されます。
残念ながら、モデルのデータ型を変更できません
マッピングでDatatupeを変更する方法はありますか..以下のようなもの
.ForMember(dest => dest.IntphoneNo,
opt => opt.MapFrom(src => src.Int32(Stringphoneno));
いくつかの調査の後、私は一歩進んだ..
私のStringPhoneNoが= 123456の場合、次の
コードが機能しています。文字列に解析する必要はありません
Mapper.CreateMap<SourceClass, DestinationClass>()
.ForMember(dest => dest.IntphoneNo,
opt => opt.MapFrom(src => src.Stringphoneno));
しかし、私の StringPhoneNo が = 12 3456 ( 12 の後にスペースがある) の場合、私のコードは機能しません。automapperで Stringphoneno (Web サービスから取得している Stringphoneno) のスペースをトリミングする方法はありますか。
以下のようなもの..
Mapper.CreateMap<SourceClass, DestinationClass>()
.ForMember(dest => dest.IntphoneNo,
opt => opt.MapFrom(src => src.Trim(Stringphoneno)));