草庐IT

query-parameters

全部标签

c# - MVC : The parameters dictionary contains a null entry for parameter 'k' of non-nullable type 'System.Int32'

我是MVC的新手。在我的应用程序中,我正在从Mydatabase中检索数据。但是当我运行我的应用程序时,它会显示这样的错误这是我的网址http://localhost:7317/Employee/DetailsData/4ExceptionDetails:System.ArgumentException:Theparametersdictionarycontainsanullentryforparameter'k'ofnon-nullabletype'System.Int32'formethod'System.Web.Mvc.ActionResultDetailsData(Int32)

c# - linq 问题 : querying nested collections

我有一个Question类,它具有可以包含多个Answers的公共(public)List属性。我有一个问题存储库,负责从xml文件中读取问题及其答案。所以我有一个问题集合(列表),每个问题对象都有一个答案集合,我想通过使用Linq查询这个问题集合的答案(即通过它的名称)。我不知道如何正确执行此操作。我可以用foreach来完成,但我想知道是否有纯Linq方式,因为我正在学习它。 最佳答案 寻找答案。questions.SelectMany(q=>q.Answers).Where(a=>a.Name=="SomeName")找到问题

c# - SQL : Update a row and returning a column value with 1 query

我需要更新表中的一行,并从中获取列值。我可以这样做UPDATEItemsSETClicks=Clicks+1WHEREId=@Id;SELECTNameFROMItemsWHEREId=@Id这会生成2个计划/访问表。是否可以在T-SQL中修改UPDATE语句以更新和返回仅具有1个计划/访问权限的名称列?我正在使用C#、ADO.NETExecuteScalar()或ExecuteReader()方法。 最佳答案 你想要OUTPUT子句UPDATEItemsSETClicks=Clicks+1OUTPUTINSERTED.NameWH

C# 4.0 : Can I use a Color as an optional parameter with a default value?

这个问题在这里已经有了答案:C#4.0:CanIuseaTimeSpanasanoptionalparameterwithadefaultvalue?(8个答案)关闭9年前。publicvoidlog(Stringmsg,Colorc=Color.black){loggerText.ForeColor=c;loggerText.AppendText("\n"+msg);}这会导致c必须是编译时常量的错误。我已经阅读了一些内容,大多数示例都在处理字符串和整数。我发现我可以使用colorconverter类,但我不确定它是否非常有效。有没有办法将基本颜色作为可选参数传递?publicvoi

c# - 错误 : "The specified LINQ expression contains references to queries that are associated with different contexts"

我从LINQ查询中收到标题中显示的错误,该查询包含来自两个不同edmx文件的两个表。这是查询:varquery=(fromaindb1.Table1joinbindb1.Table2ona.Idequalsb.Idorderbya.Statuswhereb.Id==1&&a.Status=="new"selectnew{Id=a.Id,CompanyId=(fromcindb2.Companywheres.Id==a.Idselectnew{c.CompanyId})});db1和db2是与两个不同的edmx文件关联的上下文。我该如何克服这个错误? 最佳答案

c# - Entity Framework : How to disable lazy loading for specific query?

有什么方法可以禁用EntityFramework6上特定查询的延迟加载吗?我想经常使用它,但有时我想禁用它。我正在使用虚拟属性来延迟加载它们。 最佳答案 在要执行的查询前设置如下代码context.Configuration.LazyLoadingEnabled=false; 关于c#-EntityFramework:Howtodisablelazyloadingforspecificquery?,我们在StackOverflow上找到一个类似的问题: htt

c# - ReSharper 好奇号 : "Parameter is only used for precondition check(s)."

为什么ReSharper会根据这段代码来评判我?privateControlGetCorrespondingInputControl(SupportedTypesupportedType,objectsettingValue){this.ValidateCorrespondingValueType(supportedType,settingValue);switch(supportedType){caseSupportedType.String:returnnewTextBox{Text=(string)settingValue};caseSupportedType.DateTime:

c# - "Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions"错误

为什么我收到错误:Templatescanbeusedonlywithfieldaccess,propertyaccess,single-dimensionarrayindex,orsingle-parametercustomindexerexpressions在此代码处:@modelIEnumerable@{ViewBag.Title="Index";Layout="~/Views/Shared/_PageLayout.cshtml";}Index@Html.ActionLink("CreateNew","Create")@foreach(variteminModel){@Html.

C# 4.0 : Can I use a TimeSpan as an optional parameter with a default value?

这两个都会产生一个错误,指出它们必须是编译时常量:voidFoo(TimeSpanspan=TimeSpan.FromSeconds(2.0))voidFoo(TimeSpanspan=newTimeSpan(2000))首先,有人能解释一下为什么这些值不能在编译时确定吗?有没有办法为可选的TimeSpan对象指定默认值? 最佳答案 您可以通过更改签名轻松解决此问题。voidFoo(TimeSpan?span=null){if(span==null){span=TimeSpan.FromSeconds(2);}...}我应该详细说明

c# - 不一致的可访问性 : Parameter type is less accessible than method

我试图在两种形式之间传递一个对象(基本上是对当前登录用户的引用)。目前,我在登录表单中有以下内容:privateACTInterfaceoActInterface;publicvoidbutton1_Click(objectsender,EventArgse){oActInterface=newACTInterface(@"\\actserver\Database\Premier.pad",this.textUser.Text,this.textPass.Text);if(oActInterface.checkLoggedIn()){//userhasauthedagainstACT,