********** UPDATE WITH SCREEN SHOT **************** The first fix apply did correct an occurrence of this issue, when deleting listitem and trying to save a different object.

But when I have 2 lists with the same basetype like in this sample AvailableSolidRoutes & AvailableLiquidRoutes with AvailableRoute as the base type.

GetEntityGraph fails when I delete the last AvailableSolidRoute and AvailableLiquidRoutes are empty. I know this struture works because if I call getEntityType and getChanges passing these types in.. the save persists to the db.

So this error only happens when deleting the last item from either list type when the other list type is empty.

Here is a screen shot enter image description here

Steps to reproduce:

1)Delete an AvailableSolidRoute

2)Call datacontext.saveChanges()

3)Add AvailableLiquidRoute

4)Call datacontext.saveChanges()

The getEntityGraph method fails when trying to save a different entity after successfully saving a deleted entity because it still detects the deleted entity marked as detached.

I am under the impression that an entity marked as detached is not visible to the manager

This is my dataContext save code (client side)

        function buildEntityGraphPath(entity) {

        var graphPath;
        var drugOptionIdx = entity.drugOptions.length;


        while (drugOptionIdx--) {
            var drugOption = entity.drugOptions[drugOptionIdx];


            drugOption.availableRoute

            if (drugOption.availableRoutes.length > 0) {
                graphPath = 'drugOptions.availableRoutes';
            }

            if (drugOption.availableDrugForms.length > 0) {
                graphPath += ', drugOptions.availableDrugForms';
            }

            if (drugOption.availableUnits.length > 0) {
                graphPath += ', drugOptions.availableUnits';
            }
        }

        return graphPath;
     }

      function saveDictionaryChanges(entity) {

        var entityChanges = [];
        var graphPaths = buildEntityGraphPath(entity);

        var graph = manager.getEntityGraph(entity, graphPaths);//'drugOptions.availableRoutes, drugOptions.availableDrugForms');

        // Filter for changes only  
        graph = graph.filter(function (entity) {
            return entity.entityAspect.entityState !== breeze.EntityState.Unchanged;
        });

        return manager.saveChanges(graph)
            .then(saveSucceeded, saveFailed);

        function saveSucceeded(result) {
            //TODO: Commented out because WIP is on the back burner
            //zStorage.save();


            logSuccess('Saved Data', result, true);
        }

        function saveFailed(error) {
            var msg = config.appErrorPrefix + 'Save failed: ' +
                breeze.saveErrorMessageService.getErrorMessage(error);
            error.message = msg;

            logError(msg, error);
            throw error;

        } 

These are the server side objects

     public class AvailableRoute {
        public int Id { get; set; }
        public int DrugOptionId { get; set; }
        public int RouteId { get; set; }
       public virtual Route Route { get; set; }
     }

    public class AvailableSolidRoute : AvailableRoute {
       public AvailableSolidRoute( ) { }
    }

   public class AvailableLiquidRoute : AvailableRoute {

      public AvailableLiquidRoute( ) { }
   }

Same here we will end up with 5 or 6 different types but for now just these 2 until I get it working. Each type has properties that are specific to the type.

   public class DrugOption {
      public int Id { get; set; }
      public int DrugId { get; set; }
      public List<AvailableRoute> AvailableRoutes{ get; set; }
      public string SpecialInstructions { get; set; }  
   }

   public class SolidOption : DrugOption  {
     public SolidOption( ) { }
    }

   public class LiquidOption : DrugOption {
    public LiquidOption( ) { }
   }

This is the parent object that contains a list of polymorphic drug options.

   public class Drug {

    public int Id { get; set; }
    public string Name { get; set; }
    public string TextLine1{ get; set; }
    public string TextLine2 { get; set; }
    public string TextLine3 { get; set; }
    public string TextLine4 { get; set; }
    public int? DisplayOrder { get; set; }

    public List <DrugOption> DrugOptions { get; set; }

     public Drug( ) { }

  }
有帮助吗?

解决方案

I think you ran into a getEntityGraph bug ... that I just fixed. If I am right about the issue you are reporting, that function stumbled (deep inside) upon a null reference rather than on a detached entity.

See my updated answer here.

The corrected version will appear in the next official release. You can get the current getEntityGraph.js from github right now.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top