我有我的MVC應用程序內的下列視圖模型類: -爲什麼將「System.Collections.Generic.IEnumerable」到System.Collections.Generic.IEnumerable被認爲是一個錯誤
public class CustomerDetails
{ public AccountDefinition AccountDefinition {get; set;}
public SDOrganization SDOrganization {get; set;}
public IEnumerable<SiteDefinition> SiteDefinition { get; set; }
public IEnumerable<AaaPostalAddress> AaaPostalAddress { get; set; }
public IEnumerable<AaaContactInfo> AaaContactInfo { get; set; }
public IEnumerable<SDUser> SDUser { get; set; } }
英熱單位,如果我嘗試寫這個查詢: -
var customerDetails = entities.AccountDefinitions
.Where(a => a.ORG_ID == id)
.Select(cd => new CustomerDetails
{
AccountDefinition = cd,
SDOrganization = cd.SDOrganization,
AaaPostalAddress = cd.SDOrganization.AaaPostalAddresses,
AaaContactInfo = cd.SDOrganization.AaaContactInfoes,
SiteDefinition = cd.SiteDefinitions,
SDUser = cd.SiteDefinitions.Select(p => p.UserSiteMappings.Select(p2 => p2.SDUser))//this is raising the error
})
.SingleOrDefault();
return customerDetails;
}
我會收到以下錯誤: -
Cannot implicitly convert type
System.Collections.Generic.IEnumerable<System.Collections.Generic.IEnumerable<TMS.Models.SDUser>>
toSystem.Collections.Generic.IEnumerable<TMS.Models.SDUser>
. An explicit conversion exists (are you missing a cast?)
那麼,什麼是錯的用我的代碼?
讀取您正試圖轉換的IE>到IE 的錯誤,這就是爲什麼它會失敗。 –
tschmit007