I puzzle over this problem. I found something on the Internet about this, but not a clear answer. My problem:
I have classes in the Model section of the MVC3 web application: ParentClass and ChildClass. In ParentClass, there is a List property called Children
I used EF Code First, which neatly generates a parent table and a child table for me in the database.
Now I need a REST service that returns a list or a separate ParentClass.
When I remove the Children property from ParentClass, there is no problem. But with propoerty Children there I always get an error message.
Error: "The type System.Data.Entity.DynamicProxies.ParentClass_A0EBE0D1022D01EB84B81873D49DEECC60879FC4152BB115215C3EC16FB8003A was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically."}
Some codes:
Classes:
public class ParentClass { public int ID { get; set; } public string Name {get;set;} public virtual List<ChildrenClass> Children { get; set; } } public class ChildrenClass { public int ID { get; set; } public string MyProperty { get; set; } }
Services:
[ServiceContract] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] [ServiceBehavior(IncludeExceptionDetailInFaults = true)] public class MyService { static MyContext db; public MyService() { db = new MyContext(); } [WebGet(UriTemplate = "")] public List<ParentClass> GetParents() { var result = db.Parents.ToList(); return result; }
I will not get the result when I call this service. What am I doing wrong?
rest asp.net-mvc-3 entity-framework ef-code-first wcf-web-api
Mounhim Nov 17 2018-11-11T00: 00Z
source share