在实体框架中加载子项

时间:2014-11-13 16:51:44

标签: asp.net-mvc-5 lazy-loading entity-framework-6

 public class Property : Item
{
public virtual ICollection<PropertyImage> 
                            PropertyImages
    {get; set;}

}

 public class PropertyImage
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int             ID
    {get; set;}

    public string           FileName
    {get; set;}

    public bool           IsFeatured
    {get; set;}

    public string
                            FileGuid
    {get; set;}

    [ForeignKey("Property")]
    public int             PropertyID
    {get; set;}

    public virtual Property     
                            Property
        {get; set;}
}

我必须在通过此方法请求财产清单时加载我的所有“propertyImages”

public IEnumerable<TEntity> GetMany(Expression<Func<TEntity, bool>> where, int count, params string[] includes)
    {
        var model = this.DbSet.AsExpandable().Where(where);

        foreach (var property in includes)
        {
            model.Include(property);
        }

        if (count > 0)
            return model.Take(count);
        else
            return model;
    }

问题是不起作用,为每个属性加载了propertyImages列表(我有超过200个重复请求)

0 个答案:

没有答案