我在我的 asp.net mvc wen 应用程序中定义了以下模型类:-
public class CustomerDetails
{
public AccountDefinition AccountDefinition {get; set;}
public SDOrganization SDOrganization {get; set;}
public ICollection<SiteDefinition> SiteDefinition { get; set; }
public ICollection<AaaPostalAddress> AaaPostalAddress { get; set; }
public ICollection<AaaContactInfo> AaaContactInfo { get; set; }
public virtual ICollection<UserSiteMapping> UserSiteMapping { 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,
UserSiteMapping = cd.SiteDefinitions.Select(p2 => p2.UserSiteMappings) //this is raising the exception
})
.SingleOrDefault();
return customerDetails;
但我得到了以下误导性错误:-
无法将类型“System.Collections.Generic.IEnumerable>”隐式转换为“System.Collections.Generic.ICollection”。存在显式转换(您是否缺少演员表?)
我不知道究竟是什么导致了错误,因为我正在选择UserSiteMapping
与 SiteDefinition 相关的,并且我将这些分配给 UserSiteMapping 的集合(在我的视图模型中定义)????