首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Devexpress XPO上删除旧密钥后创建欺骗密钥?

如何在Devexpress XPO上删除旧密钥后创建欺骗密钥?
EN

Stack Overflow用户
提问于 2014-10-31 10:53:58
回答 1查看 666关注 0票数 0

这是我的产品类别:

代码语言:javascript
复制
  public class Product : XPLiteObject
    {
       public string productId {get;set;}
    }

我使用Gridview来控制数据。当我用productId =“id-5”删除一行时;

代码语言:javascript
复制
gridview1.deleteSelectedRows();

然后添加带有productId =“id -5”的新行;(删除相同的id i)

最后,我说;

代码语言:javascript
复制
unitOfWork1.CommitChanges();

和例外收到:找到了一把假钥匙!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-03 08:47:38

似乎没有从数据库中删除相应的记录。有三个可能的原因:

  1. 如果GridView绑定到XPCollection,请确保将XPCollection.DeleteObjectOnRemove属性设置为true。否则,GridView.DeleteSelectedRows方法仅从集合中删除对象;
  2. 如果通过GridView绑定到XPCollection,则还需要在执行GridView.DeleteSelectedRows之后执行UnitOfWork.CommitChanges方法。否则,您的更改将不会提交到数据库;
  3. 如果产品类使用DeferredDeletionAttribute修饰,则删除该对象将设置相应的布尔列值,但实际上不会从数据库中删除记录。如果是这样的话,有四种解决问题的方法:
代码语言:javascript
复制
- Disable the Deferred Deletion feature at this class by setting the [DeferredDeletionAttribute.Enabled](https://documentation.devexpress.com/#XPO/DevExpressXpoDeferredDeletionAttribute_Enabledtopic) property to false;
- Make sure that objects you are adding are always have a unique value in the key property;
- Instead of creating a new object with the key that is already used, restore the deleted one: [How to restore deleted objects (records)](https://www.devexpress.com/Support/Center/Question/Details/A753)
- You can physically remove from the database records being marked deleted. Use the [Session.PurgeDeletedRecords](https://documentation.devexpress.com/#XPO/DevExpressXpoSession_PurgeDeletedObjectstopic) method for this purpose.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26672931

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档