I'm getting
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
for the following query in my table adapter.
select
f.id, f.name, p.productid, p.masterproductID, f.productid, f.dateCreated, f.retired, p.code as HTM开发者_JAVA技巧L_DisplayName, p.ThumbnailID, p.code
from FormSaveData f
inner join Products p on (f.productid = p.ProductID or f.productId = p.MasterProductID)
where f.userId = 130559
and (p.b_IsArchived = 0 and p.b_IsRetired=0 and p.b_IsStaged = 0)
When I run the query on its own, it works just fine, other userIds also work just fine, so this is a very particular case. I've narrowed it down to the fact that I am inner joining on
f.productid = p.ProductID **or** f.productId = p.MasterProductID
I believe in certain rare cases this causes some kind of conflict that the table adapter does not like. I'm pretty much a novice when it comes to table adapters and SQL so any advice on how this can be better written or why this is happening would be greatly appreciated.
There are no constraints, keys or special rules set for anything in the FormSaveData table.
Looks to me that your query is returning several records with the same product_id and the table adapter expects only unique rows. I am pretty sure you can disable the behavior by setting EnforceConstraints
to false
.
If you don't need [id] to be as primary key,
Remove its primary key attribute:
on your DataSet > TableAdapter > right click on [id] column > select Delete key ...
Problem will be fixed.
精彩评论