草庐IT

delete-non-virtual-dtor

全部标签

c# - 错误 : The object cannot be deleted because it was not found in the ObjectStateManager

试图在这里处理EntityFramework,但我遇到了一些减速带......我有一个Get()方法可以正常工作并且已经过测试,但是我的Delete方法不起作用:publicstaticvoidDelete(stringname){J1Entitiesdb=newJ1Entities();db.DeleteObject(Get(name));db.SaveChanges();}但是我收到以下错误:错误:无法删除该对象,因为在ObjectStateManager中找不到它。我运行了调试器,DeleteObject中的对象是正确的...我错过了什么?谢谢。 最佳

c# - 如何检查 System.IO.File.Delete 是否成功删除文件

使用system.io.file类删除文件后:System.IO.File.Delete(openedPdfs.path);如果文件被成功删除,我需要运行一些代码。只要该方法不返回任何值,我就会在delete方法之后检查文件是否存在。如果它仍然存在,我认为操作失败。问题是,删除方法工作正常,但要删除文件需要几秒钟。Exist函数返回true,因为当时它正在检查文件是否存在。我如何确定System.IO.File.Delete(openedPdfs.path);是否成功完成?代码:FileInfofile=newFileInfo(openedPdfs.path);System.IO.Fi

java - 发电机数据库 : Delete all items having same Hash Key

考虑下表:Table(documentId:HashKey,userId:RangeKey)我如何编写代码来删除具有相同documentId的所有项目,并且最好不检索这些项目。 最佳答案 目前,您不能仅通过传递Hash键来删除所有项目,要删除一个项目,它需要Hash+Range,因为这就是它的唯一性。Youhavetoknowbothyour(hash+range)todeletetheitem.编辑:这是来自DynamoDB文档的引用链接http://docs.aws.amazon.com/amazondynamodb/lates

c# - 在 C# 对象上调用 C++/CLI delete

我正在将一些代码从C++/CLI转换为C#。其中一个对象在C++/CLI版本中具有析构函数。一些其他C++/CLI代码在使用后对该对象调用“删除”。我需要在此对象的C#版本中实现哪种方法,以便那些“删除”继续发挥相同的作用(IDisposable.Dispose、终结器或我缺少的其他东西)? 最佳答案 我会说IDisposable如果您需要确定性地处理资源,那么接口(interface)就是您要寻找的。这通常是非托管资源的情况,例如需要关闭的非托管句柄、流或数据库连接。在C++/CLI中,如果声明托管类型(refclass等),ID

c# - nhibernate "cascade="all-delete-orphan”错误

我的数据库中有3个表:项目(身份证、姓名)标签(id、名称)ProjectsTagss(id、projectId、tagid)如您所见,ProjectsTags表是一个桥接表这是我流畅的nhibernate映射ProjectMap.cs:Map(x=>x.Name).Not.Nullable();HasMany(x=>x.ProjectsTags).AsBag().Inverse().Cascade.AllDeleteOrphan().Fetch.Select().BatchSize(80);ProjectsTagsMap.cs:References(x=>x.Project).Not

c# - Lazy<T> 延迟加载错误 : A field initializer cannot reference the non-static field, 方法或属性

我第一次尝试使用延迟加载来初始化我的类中的进度对象。但是,我收到以下错误:Afieldinitializercannotreferencethenon-staticfield,method,orproperty.privateLazym_progress=newLazy(()=>{longtotalBytes=m_transferManager.TotalSize();returnnewProgress(totalBytes);});在.NET2.0中,我可以执行以下操作,但我更愿意使用更新的方法:privateProgressm_progress;privateProgressPro

c# - LINQ to SQL insert-if-non-existent

我想知道是否有更简单的方法来插入表中尚不存在的记录。我仍在努力培养我的LINQtoSQL技能。这是我得到的,但似乎应该有更简单的方法。publicstaticTEntityInsertIfNotExists(DataContextdb,Tabletable,Funcwhere,TEntityrecord)whereTEntity:class{TEntityexisting=table.SingleOrDefault(where);if(existing!=null){returnexisting;}else{table.InsertOnSubmit(record);//Can'tuse

c# - 如何实现异步 File.Delete/Create/Move?

由于我必须在我的应用程序中进行大量文件I/O操作,我决定异步实现它们。查看MSDN,没有File.Create、File.Delete和File.Move的异步副本。据我了解,原因是不存在用于文件删除、创建或移动的异步Win32实现,所以我最终得到以下解决方案:publicstaticTaskDeleteAsync(stringpath){Guard.FileExists(path);returnTask.Run(()=>File.Delete(path));}publicstaticTaskCreateAsync(stringpath){Guard.IsNotNullOrWhites

c# - ListView 控件中的闪烁(OwnerDraw、Virtual)

这个问题可能被认为是Flickeringinlistviewwithownerdrawandvirtualmode的后续问题.我在虚拟模式中有一个ListView控件,我尝试执行自定义绘图。项目渲染是通过以下方法覆盖完成的:protectedoverridevoidOnDrawItem(DrawListViewItemEventArgseventArgs)如引用问题中所述,自定义绘图会在鼠标悬停事件时引入闪烁。调试器告诉我发生这种情况是因为触发了过多自定义绘制事件。现在-所引用问题的公认答案告诉我们:Thisisabugin.NET'sListViewandyoucannotgetar

c# - The non-generic method cannot be used with type arguments in this context 是什么意思?

我有以下类和方法:publicclassUserManager:IDisposablewhereTUser:class,global::Microsoft.AspNet.Identity.IUserwhereTKey:global::System.IEquatable{publicvirtualTaskFindByIdAsync(TKeyuserId);和:privateApplicationUserManager_userManager;publicApplicationUserManagerUserManager{get{return_userManager??Request.Ge