GUID 00000000-0000-0000-0000-000000000000 导致合并索引冲突
我们的开发人员有一个与我的数据库对话的 linq-2-sql 项目。数据库参与合并复制。它已经使用了一段时间并且运行良好。最近的表已添加到架构中,现在在添加新记录时会导致问题。
用户收到一条错误消息,指出与合并复制自动创建的 guid 相关的索引违反了唯一约束。
据我所知,这张桌子与其他涉及的桌子没有任何不同。我从头开始重新创建了整个复制发布/订阅模型,除了一张表之外,所有内容都继续工作。
有人有什么想法吗?正在创建的 guid 显示为 00000000-0000-0000-0000-000000000000,这可以解释为什么它是重复的。为什么 linq 没有创建有效的 guid?
Our developer has a linq-2-sql project that talks to my database. The database is involved in merge replication. It has been in use for some time and was working fine. A recent table was added to the schema and now is causing problems when new records are added.
The user get's an error message stating that the index related to the guid that merge replication automatically creates is violating a unique constraint.
From what I can tell the table isn't any different than others that are involved. I have recreated the entire replication publication/subscription model from scratch and everything continues to work but that one table.
Anyone have any ideas? The guid being created appears as 00000000-0000-0000-0000-000000000000 which would explain why it's a duplicate. Why is a valid guid not being created by linq?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当您的意思是“Guid.NewGuid()”时,您是否在代码库中的某个地方使用了“new Guid()”?
Did you use "new Guid()" somewhere in your code base when what you meant was "Guid.NewGuid()"?
我也遇到过类似的问题。正如 Mark 在评论中提到的,需要正确使用 Guid()。
而是使用
I had faced the similar problem. As Mark has mentioned in the comment, the Guid() needs to be properly used.
Instead use
使用 Linq-To-SQL 时,请确保 IsDbGenerate 属性 为 true,并且数据库实际上已设置为创建 ID(通过使用 newid() 作为默认值)。
否则,请确保 .net 代码实际上正在生成 ID。
When using Linq-To-SQL, make sure the IsDbGenerated property is true and the Database actually is setup to create an ID (by using newid() as the default value).
Otherwise, make sure the .net code is actually generating IDs.
我们在研究您的建议时发现,这个特定的表是 DBML 类中唯一包含 guid 字段的表。在发布用于合并复制的数据库之前,所有其他表均已添加到 DBML(因此它们各自的 guid 字段未包含在 DBML 中)。
因此,我手动从 DBML 中的问题表中删除了 guid 字段,问题就消失了。该问题实际上是由于 LINQ 没有像在生成的类中那样创建 guid 引起的。
在这种情况下,最简单的方法是将 guid 创建留给发布触发器和 SQL 中建立的 newid() 默认值。 (它仍然在数据库中,只是不在 dbml 中)
应用程序中没有任何内容使用这些 guid 字段...这纯粹是为了 SQL 来管理我们实现的合并复制方案 - 因此从 DBML 中删除是最简单的。
What we discovered while researching your suggestions was that this particular table was the only table that included the guid field at all in the DBML class. All the other tables had been added to the DBML prior to publishing the database for merge replication (hence their respective guid fields were not included in the DBML).
So, I manually deleted the guid field from the problem table in the DBML and the problem went away. The problem was in fact caused by LINQ not creating the guid as it should in the generated classes.
In this case it was easiest to simply leave guid creation to the publication triggers and newid() default value as established in SQL. (it's still in the database, just not the dbml)
Nothing in the application uses those guid fields... it's purely for SQL to manage the merge replication scheme we've implemented - so removing from the DBML was the easiest.