简体   繁体   English

实体框架-相关实体性能

[英]Entity Framework - Related Entity Perfomance

i have an query to load related entity for an specific entity, but it´s take a 5 seconds to load data, what happened? 我有一个查询要为特定实体加载相关实体,但是加载数据需要5秒钟,这是怎么回事?

var rows = clientes.Select(c => new
        {
            c.Id,
            c.Nome,
            Telefone = String.Format("(0{0}) {1}", c.DDD, c.Telefone),
            c.Email,
            Veiculo = (from v in c.Veiculos select new { v.Id, v.Modelo, v.Chassi }),
        })
    .Skip(pageNumber > 1 ? qtdRows * (pageNumber - 1) : 0)
    .Take(qtdRows)
    .ToArray();

It seems that you join two entities but not using filter to get Veiculos of current Clientes. 似乎您加入了两个实体,但没有使用过滤器来获取当前Clientes的Veiculos。

May be you should use something like 也许你应该使用类似

var rows = clientes.Select(c => new
        {
            c.Id,
            c.Nome,
            Telefone = String.Format("(0{0}) {1}", c.DDD, c.Telefone),
            c.Email,
            Veiculo = (from v in c.Veiculos *where v.ClientId == c.Id* select new { v.Id, v.Modelo, v.Chassi }),
        })
    .Skip(pageNumber > 1 ? qtdRows * (pageNumber - 1) : 0)
    .Take(qtdRows)
    .ToArray();

But, more consistent method is to add navigation property Veiculo to entity Client and lay joining of tables on Entity Framework. 但是,更一致的方法是将导航属性Veiculo添加到实体Client,并在Entity Framework上放置表的联接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM