0
I just need to update two fields of my model. At get I pass a DTO to my App. The question is: When I go to do my update(put verb) do I need to load all the property or just the one I will update? Like this:
[Route("atualiza/{id}")]
public void AtualizaLiberacao(LiberacaoDTO libera,int id)
{
var lista = contexto.Liberacoes
.Where(l => l.IdOrcamento == id)
.Select(s =>
{
s.AutorizouReceberAtrazado = float.Parse(libera.AutorizouReceberAtrazado),
s.FlagLiberacao = 0
});
}
Only these fields will receive new values, too not. And how do I pass the text that will be updated? The id ok, but the text. I put a Liberacaodto only as an example, but I can pass the text as a string, that’s my question. In place of the object I can pass the text(string) to be modified. All this is only illustrative. You can pass two parameters through the URL instead of just id?
My service:
[AcceptVerbs("Put")]
public void putItensLiberacao(int id, [FromBody]string value)
{
}
EDIT1
[Route("atualiza/{id}")]
public void AtualizaLiberacao(LiberacaoDTO libera)
{
contexto.Liberacoes
.Where(l => l.IdOrcamento == libera.IdOrcamento)
.Select(s =>
{
s.AutorizouReceberAtrazado = libera.AutorizouReceberAtrazado;
s.FlagLiberacao = libera.FlagLiberacao;
});
}
The form above is the correct one? And how is the route with the id? What will it serve?
I guess that’s it:
[Route("atualiza/{id}/{value}")]
public void AtualizaLiberacao(int id, string value)
{
var lista = contexto.Liberacoes
.Where(l => l.IdOrcamento == id).ToList();
lista.ForEach(f =>
{
f.FlagLiberacao = 0;
f.AutorizouReceberAtrazado = value;
});
contexto.SaveChanges();
}
You’re making this mistake: The type arguments of the method "Queryable.Select<Tsource, Tresult>(Iqueryable<Tsource>, Expression<Func<Tsource, Tresult>>)" cannot be inferred based on use. Try to specify explicitly the type arguments. Autorizadorservice C: Projects Authorizationservice Authorizationservice Models Itensrelease.Cs in the lambda select
– pnet
puts a breakpoint on var= list... and checks if the parametrics have any information
– HudsonPH
It does not rotate, it is giving dick exactly in the select of the lambda. Neither compiles. I have removed the var list, because it is not necessary, because the method is a void, and still with stick.
– pnet
@pnet you need to bring the object and change only the fields, what you are doing does not work!
– novic
@Virgilionovic, what do you mean? How do I do it?
– pnet
@pnet whether you are trying to change data with
Select? that doesn’t work! that’s where you’re wrong, if you have to bring the object in full, or use another technique to update these fields.– novic
I made an edit and see if that’s it, @Virgilionovic, what do you say? If that’s it, what’s the id parameter on the route? What’s it going to do?
– pnet
@pnet no How do you change an entity’s data in the Entity framework is not bringing the object like this
var a = db.Pessoa.Find(1);and thena.Nome = "novo nome";and thendb.SaveChanges();! what you are doing is to bring information and not to save information.– novic
Got it. Select would be more for get verbs or not it? I really want an update. If it’s not Select, what would it be?
– pnet
Let’s go continue this discussion in chat.
– novic
I recommend you take a look at this: http://www.entityframeworktutorial.net/crud-operation-in-connected-scenario-entity-framework.aspx
– HudsonPH