0
我今天遇到了AutoMapper庫的奇怪行爲。爲什麼在第二種情況下string.Format不起作用?你能向我解釋爲什麼第一個案例在第二個案例拋出異常時工作?Automapper - 無法識別string.format方法
映像配置:(工作)
config.CreateMap<Person, PersonView>().
ForMember(dest => dest.FullName, opt => opt.
MapFrom(src => src.Data.Code + " - " + src.Number));
映像配置:(不工作)
config.CreateMap<Person, PersonView>().
ForMember(dest => dest.FullName, opt => opt.
MapFrom(src => string.Format("{0} - {1}", src.Data.Code, src.Number)));
投影:
using (var ctx = new MyDbContext())
{
return ctx.Persons.Include(i => i.Data).Project().To<PersonView>().ToList();
}
例外:
[LINQ to Entities可能重複無法識別MVC 4中的方法'System.String ToString()'方法](http://stackoverflow.com/questions/18233495/linq-to-entities-does-not -recognize-the-method-system-string-tostring-method) –
SO字面上充滿了像這樣的問題。你有沒有搜索? [一](http://stackoverflow.com/questions/7259567/linq-to-entities-does-not-recognize-the-method) [二](http://stackoverflow.com/questions/32337856/linq - 無法理解 - 何時轉換方法 - 一個字符串) [三](http://stackoverflow.com/questions/18233495/linq-to-entities-does-not-recognize-the- method-system-string-tostring-method) [Four](http://stackoverflow.com/questions/10079990/linq-to-entities-does-not-recognize-the-method-system-string-formatsystem-stri ) –
查爾斯是對的,它似乎與Automapper沒有任何關係。 –