Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework 微风预加载不必要的通风特性_Entity Framework_Breeze - Fatal编程技术网

Entity framework 微风预加载不必要的通风特性

Entity framework 微风预加载不必要的通风特性,entity-framework,breeze,Entity Framework,Breeze,我正在使用实体框架6.1和breeze 1.4.11。我正试图在本地存储器中保存一些数据。我的微风控制器: [HttpGet] public object Lookups() { return new { lookupItems = _contextProvider.Context.LookupItem }; } 我的EF设置: this.Configuration.Prox

我正在使用实体框架6.1和breeze 1.4.11。我正试图在本地存储器中保存一些数据。我的微风控制器:

    [HttpGet]
    public object Lookups()
    {
        return new
        {
            lookupItems = _contextProvider.Context.LookupItem
        };
    }
我的EF设置:

        this.Configuration.ProxyCreationEnabled = false;
        this.Configuration.LazyLoadingEnabled = false;
我试图加载的类:

public class LookupItem : BaseEntityInt
{

    public int LookupTypeId { get; set; }
    public string Description { get; set; }
    public int Ordinal { get; set; }
    public virtual ICollection<Party> PartyCountries { get; set; }

}
问题是,当我将其保存在本地存储中时,store使用AmplificJS保存到本地存储。AmplificJS对持久化对象调用JSON.stringify。在浏览器的控制台中,我收到以下错误:

错误:循环对象值


这是因为breeze正在自动加载lookupitem“partycountries”的导航属性,该属性本身链接回lookupitem。有人知道它为什么这么做吗?我的理解是,您必须明确使用渴望加载或使用expand属性(我没有使用),因此我无法理解它为什么会有这种行为。

可以在这里解释发生这种情况的原因-

为了避免这种情况,我相信您可以在尝试序列化的实体上使用toString方法,从而忽略相关的导航属性


我没有将此标记为重复的原因是您正在使用Amplify.js,将来可能还会有其他用户使用。

我可以向您保证Breeze没有加载相关的
PartyCountries
。要么您的服务器api将它们与“查找”查询负载一起包含,要么您在前面将它们查询到缓存中,并在它们到达时将它们连接到您的“查找”。根据您向我们展示的代码,我猜您在
em
(EntityManager)生命周期的早期加载了
PartyCountries

您可以让Breeze为您序列化实体。它负责循环引用,不包括相关的实体,还将更改的状态与序列化的实体一起存储

例如,使用:

稍后,您可以检索并导入它们:

var imported = store("Lookups"); 
var importedEntities = em.importEntities(imported);
在的帮助下,您可以存储实体的整个图形(例如,订单及其行项目)。在这里,它将应用于您的模型

// graph of queried `LookupItems` and their in-cache, related 'PartyCountries'
var graph = em.getEntityGraph(data.results, 'PartyCountries'); 

var exported = em.exportEntities(graph , false /* exclude metadata */);
store("LookupsAndCountries", exported );

谢谢,最后我做了类似的事情。我导出entityManager并使用amplify进行存储。稍后检索em,然后在本地运行查询以获得我想要的查找。我来看看getEntityGraph。我还是看不出我是如何载入PartyCountries的。我没有用过这个,它只是为ef创建一个关系,在应用程序的其他任何地方都没有用过。感谢从服务器上检查有效负载。有什么东西在缓存中放入PartyCountries。Breeze不会自己完成(BreezeJS不支持延迟加载)。还要注意,
importenties
返回它导入的实体,因此您不必重新查询
em
var imported = store("Lookups"); 
var importedEntities = em.importEntities(imported);
// graph of queried `LookupItems` and their in-cache, related 'PartyCountries'
var graph = em.getEntityGraph(data.results, 'PartyCountries'); 

var exported = em.exportEntities(graph , false /* exclude metadata */);
store("LookupsAndCountries", exported );