0
votes

I have entities with navigation properties, for example "Parent" (an object of EntityType) and "Children" (array of objects of EntityType), but when I export those entities to another manager the navigation properties "Parent" and "Children" are null or empty.

I use the next lines:

var query = entityQuery.from('Projects');
var entitiesTmp = manager.executeQueryLocally(query); //entitiesTmp have navigation properties
var exportData = manager.exportEntities(entitiesTmp);
var mgrTmp = new breeze.EntityManager(config.remoteServiceName);
mgrTmp.importEntities(exportData);
var entitiesTmp1 = mgrTmp.executeQueryLocally(query); //entitiesTmp1 doesn't have navigation properties

I have a hierarchical class with the association bidirectional:

public abstract class HClass
{        
    public HClass()
    {
        Children = new List<HClass>();
    }
    [Key]
    public int Id { get; set; }
    public Nullable<int> ParentId { get; set; }
    public string Name { get; set; }

    public virtual ICollection<HClass> Children { get; set; }
    public virtual HClass Parent { get; set; }
}

I have other classes with Inheritance:

public class AClass : HClass
{
    public string Observation { get; set; }
}

public class BClass : HClass
{
    public int Number { get; set; }
}

The DbContext in the server:

public DbSet<AClass> Projects { get; set; }
public DbSet<BClass> OtherProjects { get; set; }

Please, help me with this error.

Note: I use breeze 1.3.4

1

1 Answers

1
votes

The EntityManager.exportEntities(entitiesToExport) call only exports those entities that are passed in, not those that are navigation properties on the entities passed in. In other words we do not do a graph traversel during the export, only the top level entities are exported. Otherwise, a small export might very well bring down a significant portion of the local cache.

There are two approaches to what you want to do.

The first, and simplest, is to simply export the entire entityManager cache. i.e. EntityManager.exportEntities(), with no args.

The second is to use the breeze metadata and traverse the entity graph yourself from the top level entities on down to build up a list of entities to export. Be careful, the graph can get large very quickly.

Hope this helps.