Multiple Entity Framework Tables Breaking WCF
c#, entity-framework, entity-framework-6, wcf
Solution
The problem here is when the WCF call is returning, it attempts to serialize the objects (which includes the navigation properties as well).
public virtual Category Category { get; set; }
AND
public virtual ICollection<Category> Categories1 { get; set; }
public virtual Category Category1 { get; set; }
public virtual ICollection<Item> Items { get; set; }
If you don't need Navigation properties you can simply mark them as private OR internal.
You can also look into this link for more detail Entity Framework Navigation Properties looping issue though WCF
Problem
I didnt think I was crazy so I went back and made a sample project to reproduce and show what going on. I have 4 simple projects like below I add the EDMX to the Data Project Here is my Table Structure Here is the properties of the EDMX And the generated class Add a Reference to the WCF Service Library to the Data project Test the Wcf Client with the default tests Add a Wcf Method And her it is asking for a EF6 Reference After Adding the reference My method is like this Running the Test Client again I get this exception So I copy the connection string from the Data.Edmx project and add it to the WCF project and run the test client and get a return of this with only one table in the EDMX which is correct. But when I update the model and add multiple tables like normal it breaks. So I just added 1 more table(like below) it breaks with this error. And it is with any tables. More than one table in the model and it will not work. Is there a step I am missing? Or why are multiple tables breaking WCF with EF6.1? EDIT This breaks it as well With classes like ``` public partial class Item { public int ItemId { get; set; } public string Name { get; set; } public int CategoryId { get; set; } public virtual Category Category { get; set; } } ``` And ``` public partial class Category { public Category() { this.Categories1 = new HashSet<Category>(); this.Items = new HashSet<Item>(); } public int CategoryId { get; set; } public string Name { get; set; } public Nullable<int> ParentId { get; set; } public virtual ICollection<Category> Categories1 { get; set; } public virtual Category Category1 { get; set; } public virtual ICollection<Item> Items { get; set; } } ```