读书人

entity framework 四 查出的数据循环调

发布时间: 2013-10-18 20:53:13 作者: rapoo

entity framework 4 查出的数据循环调用了
2个实体,一个article,一个user,我要查article,但是article里有user,所以user查出来了,但是user里又有article集合,所以artclie又查出来了,如此反复,内存溢出,


public partial class article
{
public int id { get; set; }
public string title { get; set; }
public string cont { get; set; }
public Nullable<int> uid { get; set; }
public System.DateTime addtime { get; set; }
public Nullable<int> colid { get; set; }

public virtual user user { get; set; }
public virtual column column { get; set; }
}


public partial class user
{
public user()
{
// this.roleusers = new HashSet<roleuser>();
// this.articles = new HashSet<article>();
}

public int id { get; set; }
public string email { get; set; }
public string uname { get; set; }
public string upass { get; set; }

public virtual ICollection<roleuser> roleusers { get; set; }
public virtual ICollection<article> articles { get; set; }
}

我的ef查询语句是

public List<article> PageArts(int start, int limit, out int total)
{

var ll =
_ent.articles.OrderByDescending(o => o.id)
.Skip(start)
.Take(limit).ToList();
total = _ent.articles.Count();
return ll;
}

请问如果避免这种循环加载,避免user加载article集合,好像可以配置lazyload,不过不会,请指教。我的ef实体集都是vs2012自动生成的。

[解决办法]
不会啊,默认是懒惰加载的,不会造成无限递归

你是不是把懒惰加载关了?检查DataContext的Configuration.LazyLoadingEnabled属性。

读书人网 >asp.net

热点推荐