I using ef 6.13 to get some data, and return a new class data to my app.
public List<v_apply_detail2> GetApplyList()
{
using (yoyoEntities ds = new yoyoEntities())
{
return datas = ds.v_apply_detail.Select(p => new v_apply_detail2 { apply_id = p.apply_id, time_line = ds.yoyo_apply_timeline.ToList() }).ToList();
}
}
It's runing normal.
and I want to move the Select method in a New Func, and using the dbcontext yoyoEntities(ds).
Func<v_apply_detail, v_apply_detail2> SelectOutApply(yoyoEntities ds, bool includetimeline = false)
{
return (p => new v_apply_detail2
{
apply_id = p.apply_id,
time_line = includetimeline ? ds.yoyo_apply_timeline.Where(x => x.apply_id == p.apply_id).OrderByDescending(x => x.time).ToList() : null
});
}
public List<v_apply_detail2> GetApplyList()
{
using (yoyoEntities ds = new yoyoEntities())
{
return datas = ds.v_apply_detail.Select(SelectOutApply(ds,true)).ToList();
}
}
When I call the GetApplyList function , it's get a error :Entity Framework: There is already an open DataReader associated with this Connection which must be closed first.
How do I can using the dbcontext in Func<> or Expression<> ? think guys!