我有2個屬性具有相同的名稱:給予一個別名匿名類型屬性不工作
List<CustomerWithCountry> customersList = CustomerEntity.LoadCustomersSubsetForCriteria(null, 0, 100, null)
.Select(c => new { c.CODE, c.NAME, c.COUNTRY.NAME }).ToList();
它有c.Name和c.Country.Name具有相同名稱的問題。
所以我試着給c.Country.Name一個別名:
.Select(c => new { c.CODE, c.NAME, CountryName = c.COUNTRY.NAME }).ToList();
給了我以下錯誤:
Error 3 Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#3>' to 'System.Collections.Generic.List<ViewCustomersPage.CustomerWithCountry>'
算了:) 感謝 – AngelicCore 2013-04-24 10:32:35
@AngelicCore,歡迎您 – Habib 2013-04-24 11:46:40