Skip to content

Objects saved incorrectly when object removed and added in same operation #34

@bartread

Description

@bartread

Just come in from Chris. I haven't investigated at all yet:

--------Slack message log log-------

chris.liness [5:55 PM]
I have found a dapper save bug and been unable to debug it

I could probably figure out how to get the pdbs

but i figured I should let you know

teleAppointer.Campaigns.Clear();
                   _teleAppointerRepository.Save(teleAppointer);
                   teleAppointer.Campaigns.Add(campaignToAssign);
                   _teleAppointerRepository.Save(teleAppointer);

That code works

but this code doesn't: (edited)

teleAppointer.Campaigns.Clear();
                   teleAppointer.Campaigns.Add(campaignToAssign);
                   _teleAppointerRepository.Save(teleAppointer);

user.User_MST -> tele.TeleAppointerCampaignLnk -> tele.Campaign_MST

Modelled as: (edited)

[Table("[user].[USER_MST]")]
   public class TeleAppointerDto
   {
       [PrimaryKey]
       public int? UserKey { get; set; }

       [SimpleSaveIgnore]
       public string FullName { get; set; }

       [ManyToMany("tele.TELE_APPOINTER_CAMPAIGN_LNK")]
       public IList<CampaignDto> Campaigns { get; set; }
   }
[Table("[tele].CAMPAIGN_MST")]
   public class CampaignDto
   {
       [PrimaryKey]
       public int? CampaignKey { get; set; }

       public string Name { get; set; }

       public string Description { get; set; }

       [ManyToMany("[tele].CAMPAIGN_THOMPSON_CODE_LNK")]
       public IEnumerable<ThompsonCodeDto> ThompsonCodes { get; set; }

       [ManyToMany("[tele].CAMPAIGN_DATASOURCE_LNK")]
       public IEnumerable<DatasourceDto> DataSources { get; set; }

       [ManyToMany("[tele].CAMPAIGN_PROVIDER_LNK")]
       public IEnumerable<ProviderDto> ExistingProviders { get; set; }

       [SimpleSaveIgnore]
       public int Appointments { get; set; }

       public DateTimeOffset EnabledDate { get; set; }

       public DateTimeOffset? DisabledDate { get; set; }

       public int? DaysSinceMerchantLastUpdated { get; set; }

       [ManyToMany("[tele].FIELD_SELLER_CAMPAIGN_LNK")]
       public IList<FieldSellerDto> CurrentlyAssignedFieldSales { get; set; }

       [ManyToMany("[tele].TELE_APPOINTER_CAMPAIGN_LNK")]
       public IList<UserDto> CurrentlyAssignedTeleAppointers { get; set; }
   }

A Tele Appointer can only have one Campaign. I have had to turn it into a list.

--------End Slack message log-------

I'm not sure about the comment at the end - in the code samples at the top Campaigns seems to be a list in both cases. It should work either way though - as a list, or just a direct object reference in a one to one or many to one relationship.

Will chat with Chris when I have some time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions