This is a migrated thread and some comments may be shown as answers.

Cascade Delete

3 Answers 53 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Anton M.
Top achievements
Rank 1
Anton M. asked on 02 Feb 2013, 07:14 PM
Hello.
I'm using fluent mapping.

I defined two classes:
  
public class BaseContent
{
    public BaseContent()
    {
        Parameters = new List<BaseParameter>();
    }
 
    public Guid Id { get; set; }
    public Guid? ParentId { get; set; }
    public int Number { get; set; }
    public string Name { get; set; }
    public bool IsWork { get; set; }
    public string NameOfWork { get; set; }
    public string Basis { get; set; }
    public string MeasureA { get; set; }
    public string MeasureB { get; set; }
    public bool IsChanged { get; set; }
 
    public IList<BaseParameter> Parameters { get; set; }
}
 
public class BaseParameter
{
    public Guid Id { get; set; }
    public Guid WorkId { get; set; }
    public int Number { get; set; }
    public string Name { get; set; }
 
    public BaseContent Work { get; set; }
}

My mappings:
var baseContentConfiguration = new MappingConfiguration<BaseContent>();
baseContentConfiguration.MapType(x => new
    {
        x.Id,
        x.ParentId,
        x.Number,
        x.Name,
        x.IsWork,
        x.NameOfWork,
        x.Basis,
        x.MeasureA,
        x.MeasureB
    }).ToTable("BaseContents");
baseContentConfiguration.HasProperty(x => x.Id).IsIdentity(KeyGenerator.Guid);
baseContentConfiguration.HasProperty(x => x.Name).HasColumnType("nvarchar(MAX)");
baseContentConfiguration.HasProperty(x => x.NameOfWork).HasColumnType("nvarchar(MAX)");
baseContentConfiguration.HasProperty(x => x.Basis).HasColumnType("nvarchar(MAX)");
baseContentConfiguration.HasProperty(x => x.MeasureA).HasColumnType("nvarchar(MAX)");
baseContentConfiguration.HasProperty(x => x.MeasureB).HasColumnType("nvarchar(MAX)");
baseContentConfiguration.HasAssociation(x => x.Parameters)
                        .WithOpposite(y => y.Work)
                        .HasConstraint((x, y) => x.Id == y.WorkId).IsManaged().IsDependent().IsRequired();
configurations.Add(baseContentConfiguration);
 
var baseParameterConfiguration = new MappingConfiguration<BaseParameter>();
baseParameterConfiguration.MapType(x => new
    {
        x.Id,
        x.WorkId,
        x.Number,
        x.Name
    }).ToTable("BaseParameters");
baseParameterConfiguration.HasProperty(x => x.Id).IsIdentity(KeyGenerator.Guid);
baseParameterConfiguration.HasProperty(x => x.WorkId).IsNotNullable();
baseParameterConfiguration.HasProperty(x => x.Name).HasColumnType("nvarchar(MAX)");
configurations.Add(baseParameterConfiguration);

Foreign keys will appear in base, but without cascade delete for Parameters.
Tell me please what I'm doing wrong?

3 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 06 Feb 2013, 04:08 PM
Hello Anton,

I tried your code and it works as expected - all related BaseParameter instances are deleted together with the deleted BaseContent object.
Could you please elaborate a bit more on the behavior you observe on your side? If possible, please also include the code that you have and clarify where exactly it behaves differently than what you expect.

Regards,
Alexander
the Telerik team
Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
0
Anton M.
Top achievements
Rank 1
answered on 06 Feb 2013, 04:16 PM
Hello. Thanks for reply. I'm using MS SQL 2008R2 as database. I open SQL Server Management Studio and I see that created by OpenAccess foreign key for table "BaseParameters" has no cascade delete in properties
0
Alexander
Telerik team
answered on 11 Feb 2013, 08:44 AM
Hi Anton,

You are right, currently the foreign key constraints created on the database server by OpenAccess do not have the cascading delete option enabled. This functionality is entirely handled by the runtime of OpenAccess when it is enabled in your persistent model.

If this is important to you, please feel free to add an entry to our Ideas & Feedback portal.

Regards,
Alexander
the Telerik team
Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
Tags
Getting Started
Asked by
Anton M.
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Anton M.
Top achievements
Rank 1
Share this question
or