6
How can I search a single field of the table change it and save this field without having to search all fields of the table?
The reason for this is simple, I have some tables that have more than 30 columns and this has a high processing cost in the application when it is sometimes updated only one field of this table, as in the example below, I have the table Cities and just need to change the name of the city, how to search and change only the Name field?
Obs; I’m using system.data.datacontext my context is like this.
public System.Data.Linq.Table<Tabela_ScanImagen> Tabela_ScanImagens
{
get
{
return this.GetTable<Tabela_ScanImagen>();
}
}
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Tabela_ScanImagens")]
public partial class Tabela_ScanImagen : INotifyPropertyChanging, INotifyPropertyChanged
{
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
private double _Imagem;
private string _Path;
private System.Nullable<double> _Cliente;
private System.Nullable<double> _Orcamento;
private System.Nullable<double> _Documento;
private System.Nullable<double> _Alteracao;
private System.Nullable<double> _Sinistro;
private System.Nullable<double> _Seguradora;
private System.Nullable<double> _Divisao;
private string _Descricao;
}
I tried using the Entityframework.Extended package, but it only accepts the context being System.Data.Entity
Dbcontext
public void Salvar()
{
using (var dm = new DmContext())
{
var _descricao = dm.Tabela_ScanImagens
.Where(c => c.Imagem == 6)
.Select(c => c.Descricao)
.FirstOrDefault();
dm.Tabela_ScanImagens.Update(c => new Tabela_ScanImagen { Descricao = "teste" });
dm.SaveChanges();
}
}
That way it returns me the following error.
The query must be of type Objectquery or Dbquery. Name of parameter: source
Then you can use the db.Executecommand() method to update only one field. (https://msdn.microsoft.com/pt-br/library/system.data.linq.datacontext.executecommand(v=vs.110). aspx)
– Lutti Coelho
Friend, this is one of the losses we have with Orms. Not all implement partial updates, or partial recovery of server data, as this would hinder the "transparency" with which one wants to deal with mapped objects. However, is this really harming your system’s performance, or are you trying to optimize before you instrumentalize a performance test using a specific application Profiling tool? If a bottleneck really appears, make direct calls to the DBMS, and you can even embed the UPDATE with SELECT in a single call. Don’t get stuck
– Loudenvier
I’m accepting the answer below, but she didn’t answer what she really wanted.
– Marco Souza