Reputation: 2626
I have an Entity Framework 6 .edmx (EF) running with a WCF service. My db is in SQL Server 2008. I then have a WPF client CRUD app which consumes the WCF service. All is working well until I try to introduce Foreign Keys into my db tables.
I am getting strange Timeout exceptions on the client-side consumer app & after some reading, think this is something to do with default lazy loading and WCF having issues with EF & getting into an infinite loop of some sort. As soon as I remove the Foreign keys & rebuild the model, all my Linq methods return values as expected.
I am using EF code first. Is it advisable to use DTO's rather than persist changes directly to EF objects?
Obviously I want to include Foreign Key constraints in my db if possible...
Upvotes: 0
Views: 567
Reputation: 2626
WCF & Entity Framework enable lazy loading by default. This causes a Lazy loading loop hence the timeout exceptions.
I simply disabled lazy loading for my dbcontext in my service class constructor.
RegimesEntities _Context = new RegimesEntities();
public RegimesService()
{
_Context.Configuration.LazyLoadingEnabled = false;
_Context.Configuration.ProxyCreationEnabled = false;
}
Upvotes: 1