草庐IT

express-validator

全部标签

c# - 使用 System.ComponentModel.DataAnnotations.Validator 验证属性

我的实体设置为DataAnnotation验证属性,我正在尝试使用静态Validator对其进行验证类,但我得到不同的异常,这不是正确的方法吗:string_ValidateProperty(objectinstance,stringpropertyName){varvalidationContext=newValidationContext(instance,null,null);validationContext.MemberName=propertyName;varvalidationResults=newList();varisValid=Validator.TryValida

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# -/平台 :anycpu32bitpreferred is not a valid setting for option/target:library or/target:module

我创建了一个Windows服务项目,后来决定将其输出类型更改为类库,这样我就可以将服务类包含在另一个项目中,该项目将创建要作为服务安装的.exe。但是现在,当我尝试构建第一个项目时,它失败并出现错误:/platform:anycpu32bitpreferredisnotavalidsettingforoption/target:libraryor/target:module我该如何解决这个问题? 最佳答案 尝试卸载项目(在解决方案资源管理器中右键单击)编辑.csproj(右键单击解决方案资源管理器)删除true重新加载项目。

c# - 为什么我会收到 "The modifier ' virtual'is not valid for this item“错误?

我正在尝试使用以下模型创建mvc应用程序:(代码很大。我认为它对您来说更容易理解)publicclassJob{publicintJobId{get;set;}publicstringName{get;set;}publicListGetJobs(){ListjobsList=newList();jobsList.Add(newJob{JobId=1,Name="Operator"});jobsList.Add(newJob{JobId=2,Name="Performer"});jobsList.Add(newJob{JobId=3,Name="Head"});returnjobsLi

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# - Fluent Validation 不接受带有千位分隔符的数字

我有一个ASP.NETMVC5项目,其中包含针对MVC5的FluentValidation。我还在使用jQuery屏蔽插件自动将千位值添加到double值。在我的模型中:[Display(Name="Turnover")][DisplayFormat(ApplyFormatInEditMode=true,ConvertEmptyStringToNull=true,DataFormatString="#,##0")]publicdouble?Turnover{get;set;}在我看来:@Html.DisplayNameFor(model=>model.Turnover)@Html.Te

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

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