【问题标题】:Breeze import/export produce null or empty navigation propertiesBreeze 导入/导出产生 null 或空导航属性
【发布时间】:2013-05-31 07:43:32
【问题描述】:

我有具有导航属性的实体,例如“Parent”(EntityType 的对象)和“Children”(EntityType 的对象数组),但是当我将这些实体导出到另一个管理器时,导航属性“Parent”和“ Children" 为 null 或为空。

我使用下一行:

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

我有一个具有双向关联的层次类:

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; }
}

我还有其他具有继承的类:

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

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

服务器中的 DbContext:

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

请帮我解决这个错误。

注意:我使用的是微风 1.3.4

【问题讨论】:

    标签: breeze


    【解决方案1】:

    EntityManager.exportEntities(entitiesToExport) 调用只导出传入的那些实体,而不是传入的实体上的导航属性。换句话说,我们在导出期间不进行图遍历,只导出顶层实体被导出。否则,一个小的导出很可能会降低本地缓存的很大一部分。

    您想要做的事情有两种方法。

    第一个也是最简单的方法是简单地导出整个 entityManager 缓存。即 EntityManager.exportEntities(),没有参数。

    第二个是使用微风元数据并自己从顶层实体向下遍历实体图以构建要导出的实体列表。小心,图表会很快变大。

    希望这会有所帮助。

    【讨论】:

    • 第三种,最好的方法......尽管有些工作......将编写一个 EntityManager.getEntityGraphs(rootEntities, [navigationPathStringArray]) 方法,该方法返回由根和由路径标识的相关实体组成的实体集合( s)。路径应遵循 Breeze select 的语法。然后将其贡献给 Breeze 项目。我们会喜欢的。
    • 感谢您的建议,非常感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 2012-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多