ASP.net 动态数据 - OnPropertyChanging 不更新其他列

发布于 2024-07-26 22:34:55 字数 627 浏览 8 评论 0原文

这是我的代码:

 partial void OnisApprovedChanging(bool value)
 {            
    this.dateApproved = DateTime.Now;         
 }

“dateApproved”在业务逻辑中更新,但此更改未应用于数据库表。 我见过一些示例,其中每当对表进行任何编辑时都会更新 DateUpdated 列,但我只对此字段更新时更新时间戳感兴趣,并且我不确定访问该字段的最佳方式DataContext 来自此范围。

我需要实例化数据上下文并手动更新吗?

编辑做了一些更多的研究,发现一些博客建议在更新时添加业务逻辑,如下所示:

public partial class DataContext : System.Data.Linq.DataContext
{
   partial void Updateaccount(account instance)
   {
       //business logic here      
   }
}

但是,我无法确定任何方法来查明特定字段是否已更改。 有任何想法吗?

Here is my code:

 partial void OnisApprovedChanging(bool value)
 {            
    this.dateApproved = DateTime.Now;         
 }

'dateApproved' is updated in the business logic, but this change is not being applied to the database table. I've seen some examples where DateUpdated columns are updated whenever any edit to a table is made, but I'm only interested in updating the time-stamp when this field is updated and I'm not sure of the best way to access the DataContext from this scope.

Do I need to instantiate the Data-context and update it manually?

EDIT Did some more research, and found that some blogs suggested adding business logic on update like this:

public partial class DataContext : System.Data.Linq.DataContext
{
   partial void Updateaccount(account instance)
   {
       //business logic here      
   }
}

However, I cannot determine any way to find out if particular fields have changed. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∝单色的世界 2024-08-02 22:34:55

发现这是获取原始实体并进行比较的方法。

partial void Updateaccount(account instance)
{            
   account acctPriorToUpdate = accounts.GetOriginalEntityState(instance);
   if (instance.isApproved != acctPriorToUpdate.isApproved)
   {
       //Do Stuff
   }            
   this.ExecuteDynamicUpdate(instance);   
}

Found this is the way to get the original entity and do comparisons.

partial void Updateaccount(account instance)
{            
   account acctPriorToUpdate = accounts.GetOriginalEntityState(instance);
   if (instance.isApproved != acctPriorToUpdate.isApproved)
   {
       //Do Stuff
   }            
   this.ExecuteDynamicUpdate(instance);   
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文