Version: DataObjects.Net v4.3.0 (build 5605) for .NET 4.0 DB Engine: MS SQL Server 2008

Have this model:

[Serializable]
[HierarchyRoot]
[TableMapping("Persons")]
public class Person : Entity
{
    [Field, Key]
    [TableMapping("ID")]
    public int Id { get; private set; }

    [Field(Length = 32)]
    public string Name { get; set; }

    [Field(Length = 64)]
    public string Surname { get; set; }

    [Field(Length = int.MaxValue)]
    public string Hobbies { get; set; }

    [Field]
    public EntitySet<Car> Cars { get; private set; }
}

[Serializable]
[HierarchyRoot]
[TableMapping("Cars")]
public class Car : Entity
{
    [Field, Key]
    [TableMapping("ID")]
    public int Id { get; private set; }

    [Field(Length = 128)]
    public string Name { get; set; }

    [Field(Length = int.MaxValue)]
    public string Description { get; set; }

    [Field]
    [Association(PairTo = "Cars", OnOwnerRemove = OnRemoveAction.Deny, OnTargetRemove = OnRemoveAction.Cascade)]
    public Person Owner { get; set; }
}

In entity class Car i have defined association like this:

[Association(PairTo = "Cars", OnOwnerRemove = OnRemoveAction.Deny, OnTargetRemove = OnRemoveAction.Cascade)]

As i read manual then setting OnTargetRemove = OnRemoveAction.Cascade means that when person is removed than all associated cars with this person is also removed, right?

Removing person from C# code also removed associated cars, which is OK. But when i look at generated SQL foreign key in table "Cars" then this foreign key has set action "On Delete" to value "NO ACTION" which is wrong, there should be value "Cascade" like defined in code in association attribute, isnt?


Updated at 28.07.2010 18:13:48

These actions are handled purely on BLL level (i.e. by DO), so OnXxxRemove value don't affect on foreign key constraints.

I thought that, but is this right? Is there any reason why it is not also on DB foreign key?

This thread was imported from our support forum. The original discussion may contain more detailed answer.

asked Jul 28 '10 at 07:12

Peter%20%C5%A0ulek's gravatar image

Peter Šulek
492313236

edited Sep 03 '10 at 15:44

Alex%20Yakunin's gravatar image

Alex Yakunin
29713412

These actions are handled purely on BLL level (i.e. by DO), so OnXxxRemove value don't affect on foreign key constraints.

(Jul 28 '10 at 07:12) Alex Yakunin Alex%20Yakunin's gravatar image

One Answer:

The only reasons is that this adds additional (and significant) complexity, which is mostly unnecessary: we must consider implicit cascade removals in:

  • DML update routines. Toposort, etc?

  • Schema upgrade.

Actually, the simplest possible implementation of this is to ensure we do all the cascade removal by our own before DB (nearly this anyway happens now), and let DB do nothing. So we'll consider implementing this, but as far as I can judge, this is pretty low priority issue.

I tend to view on schema-related features from two different angles: 1) Necessity in standard mode. Here DO4 handles everything. Our goal is to ensure you can implement 99% of tasks relying on DO so that implementation provides nearly the same performance as in case with your own schema. If you work with schema directly in this case, it is untypical (= we don't pay much attention to this, but taking this into account). Upgrade is also mainly our own problem. 2) Necessity in legacy mode. Here you provide the schema, and our goal is to map entities to it. Currently we don't support such features as views and IDENTITY columns, but the final goal is to support them + stored procs at least. Since schema is provided by you, upgrade isn't our problem.

So my classification of this issue is based on case 1) - likely, it's just a pleasant option.

answered Jul 28 '10 at 20:06

Alex%20Yakunin's gravatar image

Alex Yakunin
29713412

Thanks for explanation. I dont really need such feature, just to know about this behaviour.

(Jul 28 '10 at 20:06) Peter Šulek Peter%20%C5%A0ulek's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA