0

I am working on an application that has the following LINQ Expresion on an EF 6.2.0 context:

context.TimedMessageSendLogs.Include(y => y.TimedMessageCriteria)

What I am not able to find is what is happening in the Include lambda expression and why it is trying to create an foreign key constraint which causes the following exception to be raised:

Exception: Introducing FOREIGN KEY constraint 'FK_dbo.CampaignSearchCriteria_dbo.UserProfile_UpdatedBy' on table 'CampaignSearchCriteria' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints

I have tried adding the constraint as described in the error log but EF ignores it and tries to create one. In digging through the TimedMessageSendLogs entity I am unable to find anything to do with CampaignSearchCriteria

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Graham Harris
  • 319
  • 1
  • 2
  • 16
  • 1
    Include doesn't define relations at all. Its only job is to eagerly load related data *in queries*. It has no effect on the schema or migrations. Relations are defined in the DbContext's `OnModelCreating` or through conventions. – Panagiotis Kanavos Aug 26 '21 at 14:35
  • Besides, the name of that FK constraint `FK_dbo.CampaignSearchCriteria_dbo.UserProfile_UpdatedBy` has nothing to do with the classes you posted. You need to look at the `CampaignSearchCriteria` configuration – Panagiotis Kanavos Aug 26 '21 at 14:38
  • this looks like a similar problem: [introducing-foreign-key-constraint-may-cause-cycles-or-multiple-cascade-paths](https://stackoverflow.com/questions/17127351/introducing-foreign-key-constraint-may-cause-cycles-or-multiple-cascade-paths) – M.Buschmann Aug 27 '21 at 09:24

0 Answers0