草庐IT

field_delete_instance

全部标签

c# - 在 ASP.NET MVC 4 C# Code First 中指定 ON DELETE NO ACTION

如何在我的模型设计中指定ONDELETENOACTION外键约束?目前,我有:publicclassStatus{[Required]publicintStatusId{get;set;}[Required][DisplayName("Status")]publicstringName{get;set;}}publicclassRestuarant{publicintRestaurantId{get;set;}[Required]publicstringName{get;set;}[Required][EmailAddress]publicstringEmail{get;set;}[R

c# - 如何使用 HttpClient 将带有 JSON 的 DELETE 发送到 REST API

我必须使用HttpClient类向包含JSON内容的RESTAPI服务发送删除命令,但无法正常工作。API调用:DELETE/xxx/current{"authentication_token":""}因为我无法在下面的语句中添加任何内容:HttpResponseMessageresponse=client.DeleteAsync(requestUri).Result;我知道如何使用RestSharp完成这项工作:varrequest=newRestRequest{Resource="/xxx/current",Method=Method.DELETE,RequestFormat=Da

c# - 错误 : "an object reference is required for the non-static field, method or property..."

这个问题在这里已经有了答案:CS0120:Anobjectreferenceisrequiredforthenonstaticfield,method,orproperty'foo'(9个回答)关闭5年前。我正在用C#创建一个应用程序。它的功能是评估给定的是否为素数以及相同的交换数是否也是素数。当我在VisualStudio中构建我的解决方案时,它说“非静态字段、方法或属性需要对象引用...”。我在使用“volteado”和“siprimo”方法时遇到了这个问题。问题出在哪里,我该如何解决?namespaceConsoleApplication1{classProgram{static

c# - 在 C# 中,如何检查 File.Delete() 是否会在不尝试的情况下成功?

在C#中,System.IO.File.Delete(filePath)将删除指定的文件,或者引发异常。如果当前用户没有删除文件的权限,它将引发UnauthorizedAccessException。有什么方法可以让我提前判断删除是否可能抛出UnauthorizedAccessException(即查询ACL以查看当前线程的身份是否具有删除指定文件的权限?)我主要想做的是:if(FileIsDeletableByCurrentUser(filePath)){/*removesupportingdatabaserecords,etc.here*/File.Delete(filePath)

c# - 属性与字段 : Need help grasping the uses of Properties over Fields

首先,我已经通读了有关该主题的一系列帖子,但由于我对封装和字段修饰符(私有(private)、公共(public)等)的理解,我觉得自己没有掌握属性。我学到的C#的主要方面之一是通过使用封装在代码中保护数据的重要性。我“认为”我理解这是因为使用修饰符(私有(private)、公共(public)、内部、protected)的能力。然而,在了解了属性之后,我在理解C#中不仅属性用途,而且数据保护的整体重要性/能力(我理解为封装)方面都感到困惑。更具体地说,当我接触到C#中的属性时,我读到的所有内容都是您应该尽可能使用它们代替字段,因为:1)它们允许您在无法直接访问字段时更改数据类型。2)

C# 错误 : "An object reference is required for the non-static field, method, or property"

我有两个类,一个用于定义算法参数,另一个用于实现算法:1类(算法参数):usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceVM_Placement{publicstaticclassAlgorithmParameters{publicstaticintpop_size=100;publicstaticdoublecrossover_rate=0.7;publicstaticdoublemutation_rate=0.001;publicstaticintchrom

c# - 从 DataReader 对象中查找 Field 的数据类型

我有以下查询:SqlCommandcmd=newSqlCommand("Selectemployee_id,lastname,firstnamefromEmployees",conn);//ExecutereaderSqlDataReaderreader=cmd.ExecuteReader();假设我想知道字段employee_id的数据类型。如何使用SqlDataReader确定这一点? 最佳答案 reader.GetFieldType(intordinal)将返回字段的.NET类型,同时:reader.GetDataTypeNa

c# - 我收到错误 "The DELETE statement conflicted with the REFERENCE constraint"

我尝试用外键截断表并收到消息:"CannottruncatetablebecauseitisbeingreferencedbyaFOREIGNKEYconstraint".我阅读了很多有关该问题的文献,并认为我通过使用delete找到了解决方案DELETEFROMtable_nameDBCCCHECKIDENT(table_name,RESEED,0)但我仍然收到错误消息:"TheDELETEstatementconflictedwiththeREFERENCEconstraint".当我尝试使用MicrosoftManagementStudio删除并执行之前的查询时DELETEFRO

c# - ASP.NET MVC : Hidden field value does not get rendered using HtmlHelper. 隐藏

我的应用程序发生了一些非常奇怪的事情:我的ViewModel中有以下属性:publicint?StakeholderId{get;set;}它在局部View中呈现如下:提交表单,相关的Controller操作生成一个id并更新模型,然后返回与更新模型相同的View我遇到的问题是隐藏字段在其第二次呈现的“值”属性中没有任何内容,即使StakeholderId现在有一个值。如果我只是自己输出值,它会显示在页面上,所以我可以通过这样做来呈现值:"/>但是助手没有获取更新的值是很奇怪的吗?(我正在使用jQuery提交表单并将操作结果呈现到div中,但我已经检查过,在jQuery对它执行任何操作

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.