Answered by:
Code First and WITH NOCHECK ADD equivalent

Question
-
Hi there,
I have a many-to-many relationship between User and Group via UserGroup table (UserId, GroupId). However, I also have some special application specific groups (e.g. Administrators) with predefined GroupId in my code, not in DB. GroupId is a GUID.
I want to be able to add an entry into UserGroup table even if the group with the given ID doesn't exist in the Group table.
Before code first, I would disable an on-add constraint when designing my tables, which would be equivalent of ALTER TABLE UserGroup WITH NOCHECK ADD CONSTRAINT FK_UserGroup_Group FOREIGN KEY (GroupId) REFERENCES Group (Id)
Is there a way to accomplish this using CodeFirst's meta-attributes? I'm not seeing anything related on ForeignKeyAttribute.
Thanks
Monday, May 21, 2012 9:57 PM
Answers
-
On 5/21/2012 5:57 PM, DashNYC wrote:> Hi there,>> I have a many-to-many relationship between User and Group via UserGroup> table (UserId, GroupId). However, I also have some special application> specific groups (e.g. Administrators) with predefined GroupId in my> code, not in DB. GroupId is a GUID.>> I want to be able to add an entry into UserGroup table even if the group> with the given ID doesn't exist in the Group table.>> Before code first, I would disable an on-add constraint when designing> my tables, which would be equivalent of ALTER TABLE UserGroup WITH> NOCHECK ADD CONSTRAINT FK_UserGroup_Group FOREIGN KEY (GroupId)> REFERENCES Group (Id)>> Is there a way to accomplish this using CodeFirst's meta-attributes? I'm> not seeing anything related on ForeignKeyAttribute.>> Thanks>That's at the database level your are talking about with T-SQL. Youcan't make EF generate a NOLOCK T-SQL statement let alone what you aretalking about.
- Proposed as answer by Allen_MSDN Tuesday, May 22, 2012 5:54 AM
- Marked as answer by DashNYC Wednesday, May 23, 2012 2:57 PM
Monday, May 21, 2012 11:07 PM
All replies
-
On 5/21/2012 5:57 PM, DashNYC wrote:> Hi there,>> I have a many-to-many relationship between User and Group via UserGroup> table (UserId, GroupId). However, I also have some special application> specific groups (e.g. Administrators) with predefined GroupId in my> code, not in DB. GroupId is a GUID.>> I want to be able to add an entry into UserGroup table even if the group> with the given ID doesn't exist in the Group table.>> Before code first, I would disable an on-add constraint when designing> my tables, which would be equivalent of ALTER TABLE UserGroup WITH> NOCHECK ADD CONSTRAINT FK_UserGroup_Group FOREIGN KEY (GroupId)> REFERENCES Group (Id)>> Is there a way to accomplish this using CodeFirst's meta-attributes? I'm> not seeing anything related on ForeignKeyAttribute.>> Thanks>That's at the database level your are talking about with T-SQL. Youcan't make EF generate a NOLOCK T-SQL statement let alone what you aretalking about.
- Proposed as answer by Allen_MSDN Tuesday, May 22, 2012 5:54 AM
- Marked as answer by DashNYC Wednesday, May 23, 2012 2:57 PM
Monday, May 21, 2012 11:07 PM -
The question was about NOCHECK . The answer is about NOLOCK , which is irrelevantSunday, February 25, 2018 1:04 AM