草庐IT

LINQ_ENABLED

全部标签

c# - LINQ 中的 "RemoveAll"怎么可能比迭代快得多?

以下代码:Listintervals=newList();Listpoints=newList();//Initializationofthetwolists//[...]foreach(varpointinpoints){intervals.RemoveAll(x=>x.Intersects(point));}当列表的大小为~10000时,至少比这快100倍:Listintervals=newList();Listpoints=newList();//Initializationofthetwolists//[...]foreach(varpointinpoints){for(int

c# - 在 MembershipUserCollection 上使用 Linq

我有这段代码,它通过使用我的成员(member)提供程序为我提供了所有用户的列表。varusers=Membership.GetAllUsers();varusernames=newList();foreach(MembershipUserminusers)usernames.Add(m.UserName);我认为使用LINQ应该有更简单的方法来执行此操作,但我似乎无法在MembershipUserCollection上使用LINQ 最佳答案 因为MembershipUserCollection只实现了IEnumerable,不是I

c# - 如何使用 LINQ 查找 DataGridView 行?

有没有什么方法可以使用LINQ样式查询来查找DataGridView行?我正在尝试找到绑定(bind)到特定对象的对象并突出显示它。MyDatagrid.Rows.FirstOrDefault(r=>r.DataBoundItem==myItem).Selected=true;Error1'System.Windows.Forms.DataGridViewRowCollection'doesnotcontainadefinitionfor'FirstOrDefault'andnoextensionmethod'FirstOrDefault'acceptingafirstargument

c# - 将简单的 SQL group-by 转换为 LINQ to SQL

我遇到了麻烦。我无法理解StackOverflow上对此的现有答案,而且我对LINQtoSQL太陌生,无法自己解决。查看此SQL:selectp.NameasProductName,SUM(o.NumberOf)asTotalOrderedfrom[Order]ojoin[Product]pono.ProductId=p.Idgroupbyp.Name返回一个漂亮的2列表,左侧是产品名称,右侧列是已订购(所有订单)的产品总数。我如何在LINQtoSQL中复制它?这是我到目前为止所得到的:varctx=newDataClasses1DataContext();vartotalProduc

c# - 使用 LINQ 拆分列表中的项目

我想分开列表中的每个项目,但也在每个项目中,拆分项目,如果它包含:例如。string[]names={"Peter:John:Connor","Paul","Mary:Blythe"};name.Dump();将显示:Peter:John:ConnorPaulMary:Blythe但是,有没有我可以使用的LINQ,它将提供以下列表:PeterJohnConnorPaulMaryBlythe我可以使用:foreach(varpersoninnames){x=person.split(":").ToList();foreach(varpersoninlistinx){//personinl

c# - 在 Lambda/LINQ 中组合列表

如果我有IEnumerable>类型的变量是否有LINQ语句或lambda表达式我可以应用于它,它将组合返回IEnumerable的列表? 最佳答案 SelectMany-即IEnumerable>someList=...;IEnumerableall=someList.SelectMany(x=>x);对于someList中的每个项目,这然后使用lambda“x=>x”为内部项目获取IEnumerable。在这种情况下,每个“x”都是一个List,它已经是IEnumerable。然后将这些作为连续block返回。本质上,Selec

c# - LINQ to Entities Group By 表达式给出 'Anonymous type projection initializer should be simple name or member access expression'

我在这个表达式中遇到了上述错误:varaggregate=fromtinentities.TraceLinesjoinminentities.MethodNames.Where("it.NameLIKE@searchTerm",newObjectParameter("searchTerm",searchTerm))ont.MethodHashequalsm.MethodHashwhere(t.CallTypeId&(int)types)==t.CallTypeId&&t.UserSessionProcessId==m_SessionIdgrouptbym.Nameintodselect

c# - LINQ to Entities 无法识别方法 'Int32 Int32(System.String)' 方法,并且无法将此方法翻译成存储表达式

我正在尝试使用LinqtoEntities查询数据库上下文,但出现此错误:LINQtoEntitiesdoesnotrecognizethemethod'Int32Int32(System.String)'method,andthismethodcannotbetranslatedintoastoreexpression.`代码:publicIEnumerableGetCourseName(){varcourse=fromoinentities.UniversityCoursesselectnewCourseNames{CourseID=Convert.ToInt32(o.Course

c# - 如何使用 Linq 查询 Azure 存储表?

我不确定具体在哪里,但我在某处有错误的想法。首先,我尝试使用linq查询azure存储表。但我无法弄清楚它是如何完成的。通过查看各种来源,我得到以下信息:Listblogs=newList();CloudStorageAccountstorageAccount=CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("BlogConnectionString"));CloudTableClienttableClient=storageAccount.CreateCloudTableClient();C

c# - LINQ:从字典中获取给定值列表的键,反之亦然

我的代码中有以下结构Dictionarydata;.我对这两种数据类型都运行了一些LINQ查询,并且经常需要在Keys之间切换和Values.获取给定值的键列表的最佳方法是什么,反之亦然?请注意,由于我以前的LINQ查询,我通常有'IEnumerable'和'IEnumerable'并且想要像IEnumerableDictionary.GetAllKeys(IEnumerablevals)这样的东西和IEnumerableDictionary.GetAllValues(IEnumerablekeys).也许我需要其他数据容器来完成这项任务?问候,亚历山大。