如何让 Linq-to-SQL 忽略由 INSERT 触发器修改的列?

发布于 2024-09-24 18:37:24 字数 438 浏览 1 评论 0原文

我的一个表上有一列正在由数据库中的各种 INSERT/DELETE 触发器进行更新 - 触发器根据链接表的内容执行一些计算,并将结果存储在基表上的列中以便于查询等。

当我尝试更新这些表时,Linq-to-SQL 抛出 ChangeConflictException - 可能是因为触发器正在修改此列,因此 L2S 认为存在数据冲突。

我正在寻找的确切行为如下:

  • L2S 应该在检索对象时检索此列值
  • L2S 应该忽略对此列值的更改 - 代码中所做的更改不应保留到数据库
  • 冲突应该忽略保存。
  • (如果可能的话)应该在任何插入/更新操作之后从数据库中检索最新值 - 但如果这很困难的话,我可以没有这个值。

谁能帮我在 Linq-to-SQL 中实现这种行为?

谢谢,

迪伦

There's a column on one of my tables that's being updated by various INSERT/DELETE triggers in my database - the triggers perform some calculation based on the contents of linked tables and store the result in a column on the base table for easier querying, etc.

Linq-to-SQL is throwing a ChangeConflictException when I try to update these tables - presumably because the trigger is modifying this column and so L2S thinks there's a data conflict.

The exact behaviour I'm looking for is as follows:

  • L2S should retrieve this column value when retrieving an object
  • L2S should ignore changes to this column value - changes made in code should not be persisted to the DB
  • Conflicts on saving should be ignored.
  • (if possible) the latest value should be retrieved from the DB following any insert/update operation - but I can live without this one if it's difficult.

Can anyone help me implement this behaviour in Linq-to-SQL?

Thanks,

Dylan

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

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

发布评论

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

评论(1

夏末染殇 2024-10-01 18:37:24

您应该在 LINQ to SQL 设计器中将列配置为自动生成(就像对主键所做的那样)。这将防止这些冲突。

You should configure the columns as auto generated (just as you do with primary keys) in he LINQ to SQL designer. This will prevent these conflicts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文