There is post here that asks how to solve the circular reference error when returning a serialized object via EF4 CTP5. I ran into this same problem with a WCF web forms project a while back.
I was able to "solve" this problem in my WCF/web forms project and in my MVC3 project. I don't think it matters what type of project as this appears to be a EF serialization "thing".
I solved the problem by disabling ProxyCreation in my ObjectContext constructor like this:
public class MyObjectContext : DbContext, IDbContext
{
public MyObjectContext(string connectionStringName) : base(connectionStringName)
{
((IObjectContextAdapter)this).ObjectContext.ContextOptions.ProxyCreationEnabled = false;
}
public DbSet<Product> Products {get;set;}
//etc.
}
My question is: Could someone explain why this would seemingly solve the problem?
I think the problem has to do with navigation properties in my POCO's but after that I am stumped. Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…