1
In that question of mine Doubt Verb GET Webapi I face some mistakes because of relationships. But now taking it as a basis on account of my models, how could I consume this service? Because the Tabela1 model has relationships and I needed to bring them to the MVC that I’m using to consume... But what happens is that relationships, models, do not come filled, comes null...
My controller on Asp.net mvc:
public ActionResult Index()
{
//Varialvel resposável por receber os dados que estão no banco de dados para mostrar na tela
HttpResponseMessage resposta = cliente.GetAsync("http://meuservico/api/servico").Result;
//Se der tudo certo, é porque trouxe os dados retornando código 200
if (resposta.IsSuccessStatusCode)
{
//Formata o json para mostrar na tela
var result = resposta.Content.ReadAsAsync<IEnumerable<Tabela1>>().Result;
//retorna para a tela os json formatado
return View(result);
}
//Caso tenha dado errado, retorna somente a tela sem dado algum
return View();
}
The result variable brings the model Table 1 filled in, but their relationships do not... What could be happening?
And if you use a Include? I say Table1.Include(x => x.Table2); Works gives same shape?
– Érik Thiago
But then you’ll be using
Lambda Expressions
withFluent API
and not justLinq to SQL
. Which I think is much better, and much simpler. Just do something likedb.Tabela1.Include(t => t.Tabela2)
. But don’t forget to define relationships before.– Thiago Lunardi
So, in the web api I did so and it worked... But it’s in ASP.net MVC... How can I consume this way? You already have all the relationships...
– Érik Thiago
Linq, Lambda Expressions, Fluent api, none has dependency with System.web. Vc can use them even with console app.
– Thiago Lunardi
You could increase the response in the way you showed me then?
– Érik Thiago