任何人都可以帮忙吗?LINQ:帮助linq查询并包含IEnumerable <string>?
我有一个linq查询嵌入到扩展方法内部,因为v.RentalStatus是一个String。我现在在我原来的查询中使用了一个组(查询非常复杂,所以我不会把它放在这里)。
的重要提示的是,v.RentalStatus = IEnumerable的,因此它可以包含之类的东西
A (meaning active)
R (meaning rented)
U (unavailable)
etc - many more
我创造什么,我想回去和存储这statusStringList列表,以便例如让我们说该列表包含A和R
这是我的代码从v.RentalStatus只是一个字符串之前,任何人都可以告诉我如何修改此工作。
var statusStringList = rentalStatus.ToList().ConvertAll<string>(st => st.GetStringValue());
return from v in qry
where statusStringList.Contains(v.RentalStatus)
select v;
如果有帮助,这是我的查询的一部分返回RentalStatus - 一组查询它的一部分,但RentalStatus是不是该组由
RentalStatus= g1.Select(j => j.IdRentalStatus).Distinct(),
G1是我组通过,所以如果你想象有10个“A”,5个“U”......那么它会返回一个A和U的ienumerable ......因为我使用了Distinct。没有10和5我们
我希望我已经很好地解释了,请告诉我,如果我没有
我将不胜感激任何人的帮助..
感谢
编辑
这是我的扩展签名,但并不重要。
public static IQueryable<Rentals> WithStatus(this IQueryable<Rentals> qry, IList<Contants.Statuses> rentalStatus)
{
编辑
正如前面提到的,当v.RentalStatus是它正在一个字符串,但现在它的IEnumerable - 与此
Argument '1': cannot convert from 'System.Collections.Generic.IEnumerable<string>' to 'string'
你可以修复你的帖子的标题,你忘了E在IEnumerable?谢谢 – 2009-11-09 17:53:02
谢谢MArcel,我已经更新了.. oops – 2009-11-09 17:57:22