DLINQ and mapping specification for cascade on delete

Hello,

I'm using Orcas June CTP 2007 and DLINQ.

I'm trying to specify an "cascade on delete" in the mapping...

[Association(Storage ="m_loMeasures", OtherKey ="ParentDeviceId")]

Code Snippet

[Table(Name ="CDevice")]

publicclassCDevice

{

...

privateEntitySet<CMeasure> m_loMeasures;

[Association(Storage ="m_loMeasures", OtherKey ="ParentDeviceId")]

publicEntitySet<CMeasure> Measures

{

get {returnthis.m_loMeasures; }

set {this.m_loMeasures.Assign(value); }

}

...

}

[Table(Name ="CMeasure")]

publicclassCMeasure

{

...

privateEntityRef<CDevice> m_oParentDevice;

privateint m_iParentDeviceId;

[Column(Storage ="m_iParentDeviceId", DBType ="int")]

publicint ParentDeviceId

{

get {returnthis.m_iParentDeviceId; }

set {this.m_iParentDeviceId =value; }

}

[Association(Storage ="m_oParentDevice", ThisKey ="ParentDeviceId")]

publicCDevice ParentDevice

{

get {returnthis.m_oParentDevice.Entity; }

set {this.m_oParentDevice.Entity =value; }

}

...

}

I thought that we should use theDeleteRule="CASCADE"attribute, but I doesn't exist ?

So how can I specify the cascade on delete with the code ?

Thanks

[5642 byte] By [sheseh] at [2008-1-8]
# 1

There is a DeleteRule property on the Association attribute. The designer does not set it, but SqlMetal.exe does. It also may not do what you think it might. LINQ to SQL only sees that property as information to use if you call CreateDatabase. LINQ to SQL does not simulate cascade delete behaviors, it relies on the database to do that.

MattWarren-MSFT at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,LINQ Project General...
# 2

Thanks

Yes that's what I want : I didn't generate the mapping, I wrote it myself.

I want to create the database structure via CreateDatabase, and the DeleteRule is designed to add the Cascade property on the association in the DB.

Actually except the cascade property, it's working.

BUT I can't compile the "DeleteRule" attribute as the compiler says it doesn't know it.

?
sheseh at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,LINQ Project General...
# 3

Actually, I try to do it like this :

Code Snippet

[Association(Storage = "m_loMeasures", OtherKey = "ParentDeviceId", DeleteRule="CASCADE")]

public EntitySet<CMeasure> Measures

{

get { return this.m_loMeasures; }

set { this.m_loMeasures.Assign(value); }

}

Is there something wrong ?

sheseh at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,LINQ Project General...

Visual Studio Orcas

Site Classified