【发布时间】:2016-12-02 10:03:18
【问题描述】:
我有以下课程:
public class AuthenticateCustomerResponse
{
public EligiblePromotions EligiblePromotions { get; set; }
}
public class EligiblePromotions
{
public List<PromotionList> PromotionList { get; set; }
}
public class PromotionList
{
public string LineOfBusiness { get; set; }
public AuthenticatePromotions Promotions { get; set; }
}
public class AuthenticatePromotions
{
public List<AuthenticatePromotion> Promotion { get; set; }
}
public class AuthenticatePromotion
{
public string ServiceType { get; set; }
}
我想检索PromotionList 的LineOfBusiness 等于“VID”并且ServiceType 等于“SAT”。
我尝试了以下 lambda 表达式:
PromotionList getPromotion = AuthenticateCustomerResponse.EligiblePromotions.PromotionList.Find(p => p.LineOfBusiness.ToUpper().Equals("VID")).Promotions.Promotion.Find(o=>o.ServiceType.Equals("SAT"));
但我遇到了错误:
无法将类型“AuthenticatePromotion”隐式转换为 '促销清单'
我做错了什么?
【问题讨论】:
-
你的属性和类名的命名很糟糕。使用 FirstOrDefault 或在哪里会更容易。
-
@Silvermind Post 已编辑
-
您正在从您的
Promotion列表中检索AuthenticatePromotion对象。如果你只想要PromotionList,为什么还要另一个Find?