jjzjj

statement-modifiers

全部标签

c# - EntityFramework 测试初始化​​错误 : CREATE DATABASE statement not allowed within multi-statement transaction

我正在尝试构建一个快速测试,每次运行时都会删除并重新创建数据库。我有以下内容:[TestClass]publicclassPocoTest{privateTransactionScope_transactionScope;privateProjectDataSource_dataSource;privateRepository_repository=newRepository();privateconststring_cstring="DataSource=.;InitialCatalog=test_db;Trusted_Connection=True";[TestInitialize

c# - 如何在 ASP.Net 中检索上传文件的 "Last Modified Date"

我正在开发一个网站,客户端上传一些文档文件,如doc、docx、htm、html、txt、pdf等。我想检索上传文件的最后修改日期。我创建了一个处理程序(.ashx)来完成保存文件的工作。Followingisthecode:HttpPostedFilefile=context.Request.Files[i];stringfileName=file.FileName;file.SaveAs(Path.Combine(uploadPath,filename));如您所见,使用file.SaveAs()方法保存文件非常简单。但是这个HttpPostedFile类没有公开任何属性来检索文件

c# - "Items collection cannot be modified when the DataSource property is set."

很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visitthehelpcenter.关闭11年前。通过表单将文件添加到txt文件的程序有这个问题,但这个问题没有说明Fstream的任何内容,所以我认为它不必处理它,但我不确定是什么这个问题的意思是。lstEmployees.Items.Add("Norecordsfound.");

c# - 无法使用 EFCore、EntityState.Modified : "Database operation expected to affect 1 row(s) but actually affected 0 row(s)." 编辑数据库条目

我将IdentityCore1.0与ASP.NETMVCCore1.0和EntityFrameworkCore1.0结合使用来创建一个简单的用户注册系统thisarticle作为起点,我正在尝试添加用户角色。我可以添加用户角色,但无法编辑它们。这是RolesController中的Edit操作:[HttpPost][ValidateAntiForgeryToken]publicIActionResultEdit(IdentityRolerole){try{_db.Roles.Attach(role);_db.Entry(role).State=Microsoft.EntityFrame

c# - 奇怪的 "Collection was modified after the enumerator was instantiated"异常

也许有人可以为我指出正确的方向,因为我对此一头雾水。我有一个函数可以简单地打印出类的LinkedList:LinkedListcomponents=newLinkedList();...privatevoidPrintComponentList(){Console.WriteLine("---ComponentList:"+components.Count+"entries---");foreach(Componentcincomponents){Console.WriteLine(c);}Console.WriteLine("------");}Component对象实际上有一个自定

c# - 避免 InvalidOperationException : Collection was modified? 的最佳实践

我经常需要这样的东西:foreach(Linelineinlines){if(line.FullfilsCertainConditions()){lines.Remove(line)}}这不起作用,因为我总是得到一个InvalidOperationException,因为Enumerator在循环期间被更改了。所以我将所有此类循环更改为以下内容:Listremove=newList();foreach(Linelineinlines){if(line.FullfilsCertainConditions()){remove.Add(line)}}foreach(Linelineinrem

C# : Modify a xml node

我有那个xml文件:Alarm1Desc103/07/201210:11AM1None我想将Alarm1的innertext修改为另一个值,所以我编写了实际上复制整个节点的代码。XmlDocumentxml=newXmlDocument();xml.Load("0.xml");XmlNodeListelements=xml.SelectNodes("//reminders");foreach(XmlNodeelementinelements){if(element.InnerText=="Alarm1"){XmlNodenewvalue=xml.CreateElement("MODIF

c# - 错误 : Cannot find all types required by the 'async' modifier. 您是否针对错误的框架版本,或缺少对程序集的引用?

我的电脑配置如下:Windows8VisualStudio2012.NETFramework4.5我的项目配置是:WP7.1银光4.0.NETFramework4.0CTPASYNC(已安装,使用async和await关键字)该项目是使用VS2010在Windows7机器上为WP7.1编写的。现在我已经将PC升级到Windows8并安装了VS2012。然而,该项目提示“async”修饰符。无法找到“async”修饰符所需的所有类型。您是针对错误的框架版本,还是缺少对程序集的引用?知道如何解决这个问题吗?谢谢! 最佳答案 有支持Sil

c# - 我怎样才能让 VS2010 insert using statements 按照 StyleCop 规则规定的顺序

相关的默认StyleCop规则是:将using语句放在namespace中。按字母顺序对using语句进行排序。但是...Systemusing排在第一位(仍在尝试弄清楚这是否意味着只是usingSystem;或using系统[.*];).所以,我的用例:我发现了一个错误并决定我至少需要添加一个可理解的断言,以减轻下一个人调试的痛苦。所以我开始输入Debug.Assert(并且intellisense将其标记为红色。我将鼠标悬停在Debug上以及usingSystem.Diagnostics;和System.Diagnostics.Debug我选择前者。这会在所有其他using语句之后

c# - 调用使用 yield 返回的方法时出现错误 'Iterator cannot contain return statement '

我希望有更好的方法来编写此方法和重载,同时减少代码重复。我想返回列表中项目之间的一系列增量。这个方法:-publicstaticIEnumerableCalculateDeltas(thisIEnumerablesequence){decimalprev=default(decimal);foreach(variteminsequence){varcurrent=item;decimaldiff=current-prev;prev=item;yieldreturndiff;}}工作得很好。然后我想到了一个允许绝对增量的重载,但如果不需要绝对值,则会调用原始方法:-publicstati