sf.*_*sf. 1 json entity-framework-4.1 asp.net-mvc-3
我正在尝试使用ASP.NET MVC3学习Entity Framework Code First开发.
假设我有一个简单的拍卖和投标数据模型,我想查询所有拍卖及其投标.
我已经关闭了LazyLoadingEnabled和ProxyCreationEnabled.
这是我的代码:
public class MiCoreDb2Context : DbContext
{
public MiCoreDb2Context()
: base()
{
this.Configuration.LazyLoadingEnabled = false;
this.Configuration.ProxyCreationEnabled = false;
}
public DbSet<Auction> Auctions { get; set; }
public DbSet<Bid> Bids { get; set; }
}
public class Auction
{
public int AuctionId { get; set; }
public virtual ICollection<Bid> Bids { get; set; }
}
public class Bid
{
public long BidId { get; set; }
public int AuctionId { get; set; }
[ForeignKeyAttribute("AuctionId")]
public virtual Auction Auction { get; set; }
}
public JsonResult Thing()
{
List<Auction> auctions;
using (var db = new MiCoreDb2Context())
{
var auctions = (from a in db.Auctions.Include("Bids") select a).ToList();
}
return Json(auctions, JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud)
加载页面时,会出现循环引用.我该如何解决这个问题?