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

orm is dependent

1 Answer 73 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chom
Top achievements
Rank 1
Chom asked on 08 Feb 2013, 05:50 PM
Hello,
I am using the ORM fluent mapping and I have managed to create my schema etc and have just figured out the associations and got that working last night. I am still struggling to figure out the IsDependent() so that I can set up cascade deletes.

I have tried several things and am not sure if I am getting it or if I am missing something. My intepretation of cascade deletes is that I usually set it up in the Foreign Key Relationships dialog in management studio. So I am looking for the Cascade Delete to be set to true after executing my fluent code. Is that the case or am I looking in the wrong direction?

My classes are as follows:
internal class DefaultMappingDataSource : FluentMetadataSource
{
    //In order to generate DDL script for creating constraints in the database, you should override the CreateModel method.
    protected override Telerik.OpenAccess.Metadata.MetadataContainer CreateModel()
    {
        Telerik.OpenAccess.Metadata.MetadataContainer model = base.CreateModel();
        model.DefaultMapping.NullForeignKey = true;
        return model;
    }
 
    protected override IList<MappingConfiguration> PrepareMapping()
    {         
        //Define mapping configuration.
        var mappingConfig = new List<MappingConfiguration>();
 
        //Call mapping config method entities.
        var tagBankConfig = PrepareTagBankMapping();
        var abLogix5000Config = PrepareABLogix5000Mapping();
        var modbusConfig = PrepareModbusMapping();
 
        //Set upp associations.
        tagBankConfig
            .HasAssociation(e => e.ABLogixAssociation)
            .WithOpposite(p => p.TagBankAssociation)
            .HasConstraint((e, p) => e.TagBankId == p.ABLogix_TagBankId)
            .IsManaged()
            .IsDependent(true)
            .IsRequired();
 
        //abLogix5000Config
        //    .HasAssociation(e => e.TagBankAssociation)
        //    .WithOpposite(p => p.ABLogixAssociation)
        //    .HasConstraint((e, p) => e.ABLogix_TagBankId == p.TagBankId)
        //    .IsManaged()
        //    .IsDependent(true)
        //    .IsRequired();
             
        //Add the table entities to the configuration.
        mappingConfig.Add(tagBankConfig);
        mappingConfig.Add(abLogix5000Config);
        mappingConfig.Add(modbusConfig);
 
        return mappingConfig;
    }
 
    private MappingConfiguration<Tags_TagBank> PrepareTagBankMapping()
    {
        //Create mapping configuration for table columns/properties.
        var config = new MappingConfiguration<Tags_TagBank>();
 
        //Map/create table.
        config.MapType(x => new
        {
            TagBankId = x.TagBankId,
            Bank = x.Name
        }).ToTable("Banks");
        config.HasProperty(bank => bank.TagBankId).IsIdentity(KeyGenerator.Autoinc);
        config.HasProperty(bank => bank.Name).IsNullable().IsUnicode().HasLength(50);
 
        return config;
    }
 
    private MappingConfiguration<Tags_ABLogix5000> PrepareABLogix5000Mapping()
    {
        //Create mapping configuration for table columns/properties.
        var config = new MappingConfiguration<Tags_ABLogix5000>();
 
        //Map/create table.
        config.MapType(x => new
        {
            Id = x.TagId,
            ABLogix_TagBankId = x.ABLogix_TagBankId,
            TagName = x.TagName
        }).ToTable("TagsABLogix5000");
        config.HasProperty(ablogix => ablogix.TagId).IsIdentity(KeyGenerator.Autoinc);
        config.HasProperty(ablogix => ablogix.ABLogix_TagBankId).IsNotNullable();
 
        return config;
    }

public class Tags_ABLogix5000
{
    //Mapped properties.
    public int TagId { get; set; }
    public int ABLogix_TagBankId { get; set; }
    public string TagName { get; set; }
 
    //Associations
    public Tags_TagBank TagBankAssociation { get; set; }
}


public class Tags_TagBank
{
    public Tags_TagBank()
    {
        this.ABLogixAssociation = new List<Tags_ABLogix5000>();
    }
 
    //Mapped properties.       
    public int TagBankId { get; set; }
    public string Name { get; set; }
 
    //Associations
    public IList<Tags_ABLogix5000> ABLogixAssociation { get; set; }
}


I have tried using the tagbankconfig and the ablogix5000 config and see no visible result.

I would appreciate some help to solve my dilema with this issue.

Thanks

chom




 

1 Answer, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 13 Feb 2013, 04:55 PM
Hi Gavin,

 Whenever you want to specify cascading delete that must be done on the collection side of your association. If you specify it on the one side it will not work and will even ignore the setting on your collection side (as this is wrong setup).
If you only specify it on your collection side it should work as expected.

Greetings,
Petar
the Telerik team
Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
Tags
General Discussions
Asked by
Chom
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Share this question
or