草庐IT

query-expressions

全部标签

c# - Linq 和相等运算符 : Expression of type 'System.Int32' cannot be used for parameter of type 'System.Object'

我试图重写C#中的相等(==)运算符来处理任何类型与自定义类型的比较(自定义类型实际上是null周围的包装器/框)。所以我有这个:internalsealedclassNothing{publicoverrideboolEquals(objectobj){if(obj==null||objisNothing)returntrue;elsereturnfalse;}publicstaticbooloperator==(objectx,Nothingy){if((x==null||xisNothing)&&(y==null||yisNothing))returntrue;returnfal

c# - 玻璃映射器 : InferType is ignored when querying the SitecoreContext

我已经在我的Sitecore7.1解决方案上安装了Glass.Mapper.Sc.CaSTLeWindsor版本3.1.2.11包,并尝试使用推断类型。我有以下类(class):[SitecoreType]publicclassServiceConfiguration{[SitecoreField(FieldName="ServiceId")]publicvirtualstringServiceId{get;set;}}[SitecoreType(TemplateId="{26512C19-8D30-4A1E-A2CD-3BA89AF70E71}")]publicclassJavasc

c# - 林克 "Could not translate expression... into SQL and could not treat it as a local expression."

我从thisquestion开始,我有点回答there,现在我在这里问更基本的问题。我已将查询简化为:varq=fromentinLinqUtils.GetTable()fromtelinent.Telephones.DefaultIfEmpty()selectnew{Name=ent.FormattedName,Tel=tel!=null?tel.FormattedNumber:""//thisiswhatcausestheerror};tel.FormattedNumber是一种将Number和Extension字段组合成格式整齐的字符串的属性。这是导致的错误:System.Inv

c# - EF lambda : The Include path expression must refer to a navigation property

这个问题在这里已经有了答案:EF:Includewithwhereclause[duplicate](5个答案)关闭5年前。这是我的表达:Coursecourse=db.Courses.Include(i=>i.Modules.Where(m=>m.IsDeleted==false).Select(s=>s.Chapters.Where(c=>c.IsDeleted==false))).Include(i=>i.Lab).Single(x=>x.Id==id);我知道原因是模块部分的Where(m=>m.IsDeleted==false),但为什么会导致错误?更重要的是,我该如何修复它

c# - 找不到部分路径 'C:\Program Files (x86)\IIS Express\~\TextFiles\ActiveUsers.txt'

我尝试了多种方法从名为TextFiles的文件夹访问我的VisualStudio2012解决方案中的文本文件using(System.IO.StreamWriterfile=newSystem.IO.StreamWriter(@"~/TextFiles/ActiveUsers.txt",true)){file.WriteLine(model.UserName.ToString());}但是一直报错Couldnotfindapartofthepath'C:\ProgramFiles(x86)\IISExpress\~\TextFiles\ActiveUsers.txt'.不知道哪里错了

c# - Fetch 和 Query 有什么区别?

对我来说,PetaPoco的Database.Fetch和Database.Query似乎在做同样的事情。例如,vardb=newPetaPoco.Database("myDB");ProductListproducts=db.Fetch("SELECT*FROMProductList");ProductListproducts=db.Query("SELECT*FROMProductList");它们之间有什么显着的区别吗? 最佳答案 根据PetaPocodocumentation,这是答案:QueryvsFetchTheData

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# - 在 Visual C# 2008 Express Edition 中设置 32 位 x86 构建目标?

我正在构建一个加载32位COMdll的C#应用程序。编译后的应用程序在32位Windows上运行良好,但在64位Windows上运行失败,因为它无法加载32位COM。有没有办法在VC#2008ExpressEdition中设置32位构建目标?或者,是否有办法强制编译为AnyCPU构建目标的.NET应用程序在64位Windows上以32位模式运行? 最佳答案 为了后代,这里是adrian链接到的论坛帖子:InVC#Express,thispropertyismissing,butyoucanstillcreateanx86config

c# - 在 System.Linq.Expressions 中不带大小写(但使用默认值)切换

我尝试使用System.Linq.Expressions创建一个switch表达式:varvalue=Expression.Parameter(typeof(int));vardefaultBody=Expression.Constant(0);varcases1=new[]{Expression.SwitchCase(Expression.Constant(1),Expression.Constant(1)),};varcases2=newSwitchCase[0];varswitch1=Expression.Switch(value,defaultBody,cases1);vars

c# - 如何针对集合调用 Expression<Func<Entity, bool>>

我有一个从存储库模式定义存储库的接口(interface):interfaceIRepository{ListGetAllCustomers(Expression>expression);}我已经在EntityFramework上实现了它:classEntityFrameworkRepository{publicListGetAllCustomers(Expression>expression){returnDBContext.Customers.Where(expression).ToList();}}这似乎工作得很好,它允许我做类似的事情:varcustomers=entityFr