在以下场景中,我正在查询List对象,对于匹配谓词,我想更新一些值:
var updatedList = MyList
.Where (c => c.listItem1 != "someValue")
.Update (m => {m.someProperty = false;});
Run Code Online (Sandbox Code Playgroud)
唯一的问题是没有Update扩展方法.怎么去这个?
我的目标是只更新列表中符合条件的项目,其他项目保持不变.
我有以下测试代码来搜索通用列表:
public void DoSearch(string searchTerm)
{
IList<MyEntity> entities = GetCollectionOfEntities();
IList<MyEntity> results = entities.Where(d => d.Description.Contains(searchTerm)).ToList();
}
Run Code Online (Sandbox Code Playgroud)
我想通过参数传递一个订单(这将是MyEntity的一个属性),当然也可以根据它来排序我的结果.我知道LINQ使用OrderBy但不了解如何通过MyEntity的属性进行排序.
我正在寻找一种方法来对linq中的子集合进行IN子句查询.
我有一个例子如下:
Entity: Product.CategoryAssignments - this is an IList<Category> that the product is assigned to. Product can be assigned to multiple categories.
Run Code Online (Sandbox Code Playgroud)
我想检索在类别列表中匹配的所有产品,即
IList<Category> selectedCategories = GetUsersSelectedCategories();
Run Code Online (Sandbox Code Playgroud)
//怎么做的事情
IList<Products> products = from p in repository where p.CategoryAssignments.Contains(?) select p;
Run Code Online (Sandbox Code Playgroud)
任何提示赞赏?
是否可以将下面的linq查询合并到一个查询中?
var checkBoxes = from x in FindAll<CheckBox>()
where x.Checked
select new
{
RecordType = Type.GetType(x.Attributes["RecordType"]),
RecordId = Int32.Parse(x.Attributes["RecordId"])
};
checkBoxes = from x in checkBoxes
where x.RecordType != typeof(DomainModel.Group)
select x;
Run Code Online (Sandbox Code Playgroud) 我有一个ICollection<Product>:
var products = productRepository.FindAll();
Product有一个叫做的属性Orders,这是一个ICollection<Order>.
ICollection<Order>对于给定的CustomerId,我试图最终得到一个.
换一种说法:
鉴于产品集合,我想检索特定客户的订单列表
这就是我所拥有的:
var orders = products
.Where(x => x.Orders != null)
.Where(x => x.Orders.Any(y => y.CustomerId == 10))
.Select(x => x.Orders)
.ToList();
Run Code Online (Sandbox Code Playgroud)
但我最终得到了一个List<ICollection<Order>>,我想要一个ICollection<Order>.
我必须做某种分组吗?
我有一个场景,我有一个
var testVar= list1.Intersect(list2);
Run Code Online (Sandbox Code Playgroud)
testVar包含大约400个值.
现在我必须在文本框中显示所有值.喜欢:
Textbox1.text = testVar...
Run Code Online (Sandbox Code Playgroud)
因此,如果没有for循环,怎么能在TextBox中显示这些值
请帮忙
我正在尝试针对两个对象(SPListItemCollection和List<SPListItem>)编写LINQ查询.
当我的查询类似于下面的查询时它工作正常:
var licFirst = from n in navList.Items.Cast<SPListItem>()
from z in licZeroth
where ((SPFieldLookupValueCollection)n["Parent"]).Select(t=>t.LookupId).Contains(z.ID)
select n;
Run Code Online (Sandbox Code Playgroud)
当我向select中添加一个项目时:
var licFirst = from n in navList.Items.Cast<SPListItem>()
from z in licZeroth
where ((SPFieldLookupValueCollection)n["Parent"]).Select(t=>t.LookupId).Contains(z.ID)
select n, ParentId = z.ID;
Run Code Online (Sandbox Code Playgroud)
它开始出错:
名称"z"在当前上下文中不存在
我该如何选择z.ID?
我怎么能这样:
string x;
string y = x.RemoveWhere(c => !char.IsLetter(c));
Run Code Online (Sandbox Code Playgroud)
使用LINQ?
当我在我的集合中有重复项时,我想返回true,否则,我想返回false.
我有以下linq查询.
var t = from i in selectedDrivers
group i by i.Value into g
where g.Count() > 1
select g.Count() > 1;
Run Code Online (Sandbox Code Playgroud)
但问题是,当存在多个重复时,它将返回多个trues,如果没有任何重复,则不返回任何内容(应该为false).
这是我想要分组的数据.
Start End
2 4
26 30
5 9
20 24
18 19
Run Code Online (Sandbox Code Playgroud)
因为我有18 - 19和20 - 24.我会将这两个加在一起作为18 - 24.在这种情况下,规则是(a,b)=> b.start - a.end = 1,结果将是
Start End
18 24
2 9
26 30
Run Code Online (Sandbox Code Playgroud)
编辑在下面的每条评论中添加了最后的结果行