我在控制器中尝试了此代码,谁能告诉我解决方案:
public function categories()
{
return $this->hasMany(Category::class);
}
public function childs() {
return $this->hasMany(Category::class,'category_id','id') ;
}
public function parent()
{
return $this->belongsTo(Category::class,'category_id');
}
public function isParent()
{
return !$this->category_id ? true : false; // if category_id is null => is a Parent Category
}
public function products(){
return $this->hasMany(Product::class);
}
//just added
public function getBreadCrumb(){
$crumbs = array();
// handle parent
if(!empty($this->parent)){
$crumbs[] = $this->parent->getBreadCrumb();
}
$crumbs[] = '<a href="' . $this->slug . '">' . $this->title . '</a>';
return implode(">", $crumbs);
}
javascript函数
public JsonResult GetMembers(Member member)
{
//var list = repository.GetAll().Select(x => new ViewModel.MemberView
//{
// Memberid = x.id,
// Name = x.name,
// EmailAddress = x.Email,
// Role = x.role.rolename,
// ReportingRoleId = Convert.ToInt32(x.reportingroleid)
//});
var list = repository.GetAll();
return Json(list , JsonRequestBehavior.AllowGet);
}
是错误
序列化类型为'System.Data.Entity.DynamicProxies.NewProjects_A3B55EADDAEF6C59245BBD2495E29ECFE10B583596DB24AADF23A4990342D104'的对象时,检测到循环引用。
答案 0 :(得分:0)
您应先将数据转换为列表,然后再返回。 EF返回代理用于延迟加载和填充。尝试下面的代码。
var list = repository.GetAll().ToList();
也看看这个。
Why is EF returning a proxy class instead of the actual entity?
答案 1 :(得分:0)
我有同样的错误,但这对我有用,这是您要选择的时间
<ul className="nav navbar-nav navbar-right">
<li className="nav-item dropleft">
<a className="nav-link" id="walletOptions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<img src={require('../img/wallet.svg')} alt="easyfeedbacktoken" height="40px" />
</a>
<ul className="dropdown-menu" aria-labelledby="walletOptions">
<ImportMnemonicModal onUpdateMnemonic = {this.props.onUpdateMnemonic}/>
<ShowMnemonic mnemonic = {this.props.mnemonic}/>
<DeleteWallet onUpdateMnemonic = {this.props.onUpdateMnemonic}/>
</ul>
</li>
</ul>