Search code examples
c#entityvisual-studio-lightswitchlightswitch-2013

Lightswitch Updating() method not saving any data in DB


I am trying to save the entity data using General methods of lightswitch, which is Updating. Below is the following code. I am not able to figure out what I am missing. There is no error in the code or in the UI. Its just that nothing gets saved.

partial void viewFamilyProcessDatas_Updating(viewFamilyProcessData entity)
    {

        var AutoAddMissingListing = entity.AutoAddMissingListing;
        var AutoAddOddLots = entity.AutoAddOddLots;
        var DefaultFilterValue = entity.DefaultFilterValue;
        var ExcludeZeroNumberOfUnits = entity.ExcludeZeroNumberOfUnits;
        //objFamilyProcessData.FamilyID = entity.FamilyID;
        var IgnoreForPricing = entity.IgnoreForPricing;
        var LimitEndDate = entity.LimitEndDate;
        var OffsetFromMaxAsAtDate = entity.OffsetFromMaxAsAtDate;
        var PrefilterConstituents = entity.PrefilterConstituents;
        var TimeDataExpires = entity.TimeDataExpires;

        entity.AutoAddMissingListing = AutoAddMissingListing;
        entity.AutoAddOddLots = AutoAddOddLots;
        entity.DefaultFilterValue = DefaultFilterValue;
        entity.ExcludeZeroNumberOfUnits = ExcludeZeroNumberOfUnits;
        entity.IgnoreForPricing = IgnoreForPricing;
        entity.LimitEndDate = LimitEndDate;
        entity.OffsetFromMaxAsAtDate = OffsetFromMaxAsAtDate;
        entity.PrefilterConstituents = PrefilterConstituents;
        entity.TimeDataExpires = TimeDataExpires;

        //this.DataWorkspace.SolaDBServerData.Details.DiscardChanges();
        entity.Details.DiscardChanges();



    }

Solution

  • The solution to this finally came to this:

    partial void vwFamilyProcessDatas_Updating(vwFamilyProcessData entity)
        {
            if(entity.Details.EntityState.ToString() == "Modified")
            {
                var AutoAddMissingListing = entity.AutoAddMissingListing;
                var AutoAddOddLots = entity.AutoAddOddLots;
                var DefaultFilterValue = entity.DefaultFilterValue;
                var ExcludeZeroNumberOfUnits = entity.ExcludeZeroNumberOfUnits;
                var IgnoreForPricing = entity.IgnoreForPricing;
                var LimitEndDate = entity.LimitEndDate;
                var OffsetFromMaxAsAtDate = entity.OffsetFromMaxAsAtDate;
                var PrefilterConstituents = entity.PrefilterConstituents;
                var TimeDataExpires = entity.TimeDataExpires;
    
                tblFamily objFamily = tblFamilies.Where(f => f.FamilyID == entity.FamilyID).Single();
                objFamily.AutoAddMissingListing = AutoAddMissingListing;
                objFamily.AutoAddOddLots = AutoAddOddLots;
                objFamily.DefaultFilterValue = DefaultFilterValue;
                objFamily.ExcludeZeroNumberOfUnits = ExcludeZeroNumberOfUnits;
                objFamily.IgnoreForPricing = IgnoreForPricing;
                objFamily.LimitEndDate = LimitEndDate;
                objFamily.OffsetFromMaxAsAtDate = OffsetFromMaxAsAtDate;
                objFamily.PrefilterConstituents = PrefilterConstituents;
                objFamily.TimeDataExpires = TimeSpan.Parse(TimeDataExpires);
    
                entity.Details.DiscardChanges();
            }}