2017-10-07 4 views
0

anzuzeigen habe ich einen Controller:geruhsamen C# page nicht richtig

public IEnumerable<Food> Get() 
{ 
    FoodDiaryContext cs = new FoodDiaryContext(); 
    var foodquery = cs.Foods.OrderByDescending(c => c.Description).ToList(); 

    return foodquery; 
} 

Es zeigen sollte:

{ 
    id:1 
    description:food 
    measure:[] 
} 

Aber ich erhalte eine Fehlermeldung:

Type 'System.Data.Entity.DynamicProxies.Food_219DB877F13A4776536ADFD2AC86DB1FDBF0E8887DB7E9D658EFE7D9462C3BD5' with data contract name 'Food_219DB877F13A4776536ADFD2AC86DB1FDBF0E8887DB7E9D658EFE7D9462C3BD5: http://schemas.datacontract.org/2004/07/System.Data.Entity.DynamicProxies ' is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to the serializer.

public class Food 
{ 
    public Food() 
    { 
     Measures = new List<Measure>(); 
    } 

    public int Id { get; set; } 
    public string Description { get; set; } 
    public virtual ICollection<Measure> Measures { get; set; } 
} 

public class Measure 
{ 
    public int Id { get; set; } 
    public string Description { get; set; } 
    public double Calories { get; set; } 
    public double Fats { get; set; } 
    public double Protein { get; set; } 
    public double Carbohydrates { get; set; } 
    public virtual Food Food { get; set; } 
} 

Can jemand bitte sagen Sie mir, was ich falsch gemacht habe?

Danke

+0

Versuchen Sie, die Proxy-Erstellung auf Ihrem Db-Kontext zu deaktivieren, es ist kein ASP.NET-spezifischer Fehler, und versuchen Sie auch, Ihr Kontextmodell zu aktualisieren. – narekye

+0

Gibt es einen bestimmten Grund, warum Sie das Domänenmodell an den Client zurückgeben möchten? –

Antwort

0

Danke für die Hilfe. Ich wollte, dass Sie vorgeschlagen und es funktioniert.