【发布时间】:2014-04-28 13:54:26
【问题描述】:
这里我需要重用 linq 查询,在 if 和 else 条件等两个地方稍作改动。如何编写可重用的 linq 查询
if(some condition){
comms = (from s in config.PromoRegistration.Communications.Cast<CommunicationGroupConfiguration>()
from c in s.Communications.Cast<CommunicationConfiguration>()
where s.CurrentBrand == true
select c).ToList().FirstOrDefault();
}
else{
comms = (from s in config.Subscriptions.Cast<CommunicationGroupConfiguration>()
from c in s.Communications.Cast<CommunicationConfiguration>()
where s.CurrentBrand == true
select c).ToList().FirstOrDefault();
}
这里
config.PromoRegistration.Communications.Cast<CommunicationGroupConfiguration>()
仅这一部分在这两个查询中发生了变化。如何有效地编写此查询。任何建议。
【问题讨论】:
标签: c# .net linq linq-to-entities