locked
Delete entire object graph RRS feed

  • Question

  • Hi,

    I've hit a snag on my smaple mailer. I have agents and messages. A message has many reviewers who are agents. I've mapped this in the DB (primitive i know - it's a test):

    CREATE TABLE [dbo].[MessageAgentReview](
        [MessageAgentReviewID] [int] NOT NULL,
        [MessageID] [int] NULL,
        [AgentID] [int] NULL,
        CONSTRAINT [PK_MessageAgentReview] PRIMARY KEY CLUSTERED ([MessageAgentReviewID] ASC) WITH (IGNORE_DUP_KEY = OFF)
    )
    GO
    ALTER TABLE [dbo].[MessageAgentReview]  WITH CHECK ADD  CONSTRAINT [FK_MessageAgentReview_Agent] FOREIGN KEY([AgentID])
    REFERENCES [dbo].[Agent] ([AgentID])
    GO
    ALTER TABLE [dbo].[MessageAgentReview]  WITH CHECK ADD  CONSTRAINT [FK_MessageAgentReview_Message] FOREIGN KEY([MessageID])
    REFERENCES [dbo].[Message] ([MessageID])

    And have presistence fine.

    However when I remove the message... the trailling agents are left. Now in my test i create new Agents and Messages. I then link them together. Currently SQLMetal resolves the ManyToMany I have by directly mapping the link table MessageReviewerAgents to a domain object in it's own right.

    Fair enough. But when I remove both the Agent and Message I am left with a MessageReviewerAgent record.

    Is there a way to remove the entire graph (cause a cascade) when I remove the Message and Agent ? It's not terribly helpful if I'm compelled to add a facade to the domains to ensure that any mapped properties are removed. I realise this may be by design but I guess they map be a mapping setting for a cascade delete?

    Cheers
    ian
    Friday, May 26, 2006 11:56 AM

Answers

  • There are no mapping options to delete the middle entity in the many-to-many relationship.  You could  use the Delete method override that DLinq provides (via the [DeleteMethod] attribute), so that when the delete of an Agent object is done removes the MessageReviewerAgent records as well.  Triggers or Stored procs could do something similar in the database; but to removal of the MessageReviewerAgent instances would be the best approach.
    Friday, May 26, 2006 4:39 PM

All replies

  • There are no mapping options to delete the middle entity in the many-to-many relationship.  You could  use the Delete method override that DLinq provides (via the [DeleteMethod] attribute), so that when the delete of an Agent object is done removes the MessageReviewerAgent records as well.  Triggers or Stored procs could do something similar in the database; but to removal of the MessageReviewerAgent instances would be the best approach.
    Friday, May 26, 2006 4:39 PM
  • Thanks that's what I went for in the end.
    Friday, June 2, 2006 3:55 PM