更新/修剪 Lambda where 表达式中的值
我有一个 Lambda where 表达式,它根据传入的 ID 过滤客户列表。这工作正常,但是我想在返回记录时从 CreationDate 字段中删除时间戳。有没有办法在 Lambda 表达式中执行此操作?
这是我的 Lambda 表达式,它返回我的客户记录:
customers = customers.Where(c => c.Business_Type == businessType);
但是我想做如下操作:
customers = customers.Where(c => c.Business_Type == businessType, c.CreationDate=c.CreationDate.Value.ToShortDateString());
I have a Lambda where expression which filters a list of customer based on a ID passed in. This works fine however I want to remove the timestamp from the CreationDate field when I return the records. Is there anyway to do this within the Lambda expression?
So this is my Lambda expression which returns my customer records:
customers = customers.Where(c => c.Business_Type == businessType);
However I'd like to do something like the following:
customers = customers.Where(c => c.Business_Type == businessType, c.CreationDate=c.CreationDate.Value.ToShortDateString());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
LINQ 并不意味着执行序列元素的突变。只需获取
Where
的返回值并使用foreach
执行突变,这是处理此问题的惯用方法:LINQ is not meant to perform mutation of sequence elements. Just take the return value of
Where
and useforeach
to perform the mutation, which is the idiomatic way to handle this: