草庐IT

where-in

全部标签

c# - Linq:只为 Where 和 OrderBy 调用相同的方法一次而不是两次?

我有一个简单的linq查询,我需要在一定距离内过滤商店,并根据距离计算结果排序,你懂的。因此,我暂时调用了两次GetDistance方法。如何优化代码以在每个商店只调用一次?doubledistance=50;varresult=stores.Where(s=>Helper.GetDistance(lat,lon,s.Lat,s.Lon)Helper.GetDistance(lat,lon,s.Lat,s.Lon)).ToList(); 最佳答案 一些人(我)觉得更容易阅读的与Yuriy的回答等价的是:doublemaxDistan

c# - 无效操作异常 : No IAuthenticationSignInHandler is configured to handle sign in for the scheme: MyCookieAuthenticationScheme

我正在尝试按照说明进行操作here将Cookie身份验证添加到我的网站。到目前为止,我添加了以下内容:InvoketheUseAuthenticationmethodintheConfiguremethodoftheStartup.csfile:app.UseAuthentication();InvoketheAddAuthenticationandAddCookiemethodsintheConfigureServicesmethodoftheStartup.csfile:services.AddAuthentication("MyCookieAuthenticationScheme

c# - C++/命令行界面 : How do I declare abstract (in C#) class and method in C++/CLI?

以下C#代码在C++/CLI中的等价物是什么?publicabstractclassSomeClass{publicabstractStringSomeMethod();} 最佳答案 只需稍微混合关键字即可获得正确的语法。abstract在C#中位于前面,但在C++/CLI中位于末尾。与override关键字相同,今天也被C++11兼容的编译器识别,它们期望它位于函数声明的末尾。就像传统C++中的=0标记函数抽象一样:publicrefclassSomeClassabstract{public:virtualString^SomeM

c# - LINQ to Entities/LINQ to SQL : switching from server (queryable) to client (enumerable) in the middle of a query comprehension?

在许多情况下,我想在服务器端进行一些过滤(有时是投影),然后切换到客户端以执行LINQ提供程序本身不支持的操作。天真的方法(这基本上就是我现在所做的)是将其分解为多个查询,类似于:varfromServer=fromtincontext.Tablewheret.Col1=123wheret.Col2="blah"selectt;varclientSide=fromtinfromServer.AsEnumerable()wheret.Col3.Split('/').Last()=="whatever"selectt.Col4;但是,很多时候,这带来的代码/麻烦多于它的实际值(value)

c# - LINQ: ...Where(x => x.Contains(以 "foo"开头的字符串 ))

给定以下类的集合:publicclassPost{...publicIListTags{get;set;}}有没有一种简单的方法可以使用LINQ获取所有包含以“foo”开头的标签的Post?varposts=newList{newPost{Tags=new[]{"fooTag","tag"}},newPost{Tags=new[]{"barTag","anyTag"}},newPost{Tags=new[]{"someTag","fooBarTag"}}};varpostsWithFooTag=posts.Where(x=>[somefancyLINQqueryhere]);posts

c# - 使用 linq 2 实体检查 where 子句的两个条件

嗨,我有一个名为products的表,其中包含列product_idprodcut_nameprodcut_price(valueslike1200,2000,3000,100)prodcut_desccategory_id(1,2,3,.....)另一个带有列的表格类别category_id(1,2,3.......)category_name(a,b,c....)实体名称是dbcontext...如何获得类别名称为“a”且产品价格为>500且我正在使用linqtoentities...请帮忙解决这个问题......一个......非常感谢.... 最佳答

c# - DbContext -> DbSet -> Where 子句丢失( Entity Framework 6)

我已经阅读了一些EntityFramework6的教程...基础很简单。using(varcontext=newMyContext()){Useru=context.Users.Find(1);}但是如何在用户的“DbSet”上使用“Where”或其他东西呢?publicclassMyContext:DbContext{publicMyContext():base("name=MyContext"){//this.Database.Log=Console.Write;}publicvirtualDbSetUsers{get;set;}}用户[Table("User")]publiccl

c# - LINQ- Max where 条件

我有一个定义如下的TaskWeekUI类:publicclassTaskWeekUI{publicGuidTaskWeekId{get;set;}publicGuidTaskId{get;set;}publicGuidWeekId{get;set;}publicDateTimeEndDate{get;set;}publicstringPersianEndDate{get;set;}publicdoublePlanProgress{get;set;}publicdoubleActualProgress{get;set;}}我写了这个查询:TaskWeekUIti=tis.First(t=

c# - SSRS : Get list of all reports and parameters in a single web service call?

简短而贴心的版本:是否有一个单一的Web服务方法可以返回所有可用报告的名称以及每个报告的参数?我将我的网络代码(C#/MVC)连接到SSRS网络服务,并且我能够通过这些服务检索报告。我知道我可以获得像这样的可用报告列表:varrService=newReportingService2005{Url=@"http://domain.com/ReportServer/ReportService2005.asmx?wsdl",Credentials=System.Net.CredentialCache.DefaultCredentials};varreportList=rService.Li

c# - 数字必杀技 : Where does a callvirt of a non-existent method end up?

我在其基类中标记为抽象的库类上调用属性集访问器。现在在运行时我force应用程序针对另一个版本的库运行,其中类仅实现基类的底层接口(interface),但不是从它派生的。有趣的是,.NET将运行代码,但设置该属性没有任何效果。幕后发生了什么?违规代码:MyDbParameterparam=newMyDbParameter();param.ParameterName="p";Console.Out.WriteLine("ParameterName:"+param.ParameterName);库2.0(已编译)publicsealedclassMyDbParameter:System.