0
I created a method where my partner, besides receiving data from our base, also sends us. Well, this was working well. Then I discovered that a field was missing. I added this field to the interface and also to the method. Well, I don’t know if it was that or something else, but it didn’t work anymore. The error is that extracted from the server log:
System.Data.Entity.Validation.DbEntityValidationException: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details. at System.Data.Entity.Internal.InternalContext.SaveChanges() at SuporteTecnicoWS.SuporteTecnicoServiceWS.recebeDadosParceiro(String _idparceiro, String _numos, String _datavisita, String _dataagendamento, String _dataaberturaos, String _datafechamentotarefa, String _datafechamentoos, String _statusos, String _statuspdv, String _tecnico, String _tarefa_fechada) at SyncInvokerecebeDadosParceiro(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
SerializedException <Exception><ExceptionType>System.Data.Entity.Validation.DbEntityValidationException, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.</Message><StackTrace> at System.Data.Entity.Internal.InternalContext.SaveChanges() at SuporteTecnicoWS.SuporteTecnicoServiceWS.recebeDadosParceiro(String _idparceiro, String _numos, String _datavisita, String _dataagendamento, String _dataaberturaos, String _datafechamentotarefa, String _datafechamentoos, String _statusos, String _statuspdv, String _tecnico, String _tarefa_fechada) at SyncInvokerecebeDadosParceiro(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&amp; outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp; rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace><ExceptionString>System.Data.Entity.Validation.DbEntityValidationException: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details. at System.Data.Entity.Internal.InternalContext.SaveChanges() at SuporteTecnicoWS.SuporteTecnicoServiceWS.recebeDadosParceiro(String _idparceiro, String _numos, String _datavisita, String _dataagendamento, String _dataaberturaos, String _datafechamentotarefa, String _datafechamentoos, String _statusos, String _statuspdv, String _tecnico, String _tarefa_fechada) at SyncInvokerecebeDadosParceiro(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&amp; outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp; rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</ExceptionString></Exception>
AppDomain /LM/W3SVC/2/ROOT/WebServiceSuporteTecnico
This is my interface
[OperationContract]
[WebInvoke(
Method = "GET", // Tipo de request
BodyStyle = WebMessageBodyStyle.Bare, // Identação do retorno
UriTemplate = "pegastatusparceiro/{_idparceiro}/{_numos}/{_datavisita}/{_dataagendamento}/{_dataaberturaos}/{_datafechamentotarefa}/{_datafechamentoos}/{_statusos}/{_statuspdv}/{_tecnico}/{_tarefa_fechada}" // Url do serviço, onde cada {} = parametro
)]//Filter para tratar REST
T_OsParceiro recebeDadosParceiro(string _idparceiro, string _numos, string _datavisita, string _dataagendamento, string _dataaberturaos,
string _datafechamentotarefa, string _datafechamentoos, string _statusos, string _statuspdv,
string _tecnico, string _tarefa_fechada);
And that’s my method, because he only makes it in the comic
public T_OsParceiro recebeDadosParceiro(string _idparceiro, string _numos, string _datavisita, string _dataagendamento, string _dataaberturaos,
string _datafechamentotarefa, string _datafechamentoos, string _statusos, string _statuspdv,
string _tecnico, string _tarefa_fechada)
{
using (WEBEntities db = new WEBEntities())
{
T_OsParceiro parceiro = new T_OsParceiro();
parceiro.IDTarefaParceiro = Convert.ToInt32(_idparceiro);
parceiro.NumOs = Convert.ToInt32(_numos);
parceiro.DataVisita = Convert.ToDateTime(_datavisita);
parceiro.DataAgendamento = Convert.ToDateTime(_dataagendamento);
parceiro.DataAbertura = Convert.ToDateTime(_dataaberturaos);
parceiro.DataFechamentoTarefa = Convert.ToDateTime(_datafechamentotarefa);
parceiro.DataFechamento = Convert.ToDateTime(_datafechamentoos);
parceiro.StatusOS = _statusos;
parceiro.StatusPDV = _statuspdv;
parceiro.Tecnico = _tecnico;
parceiro.Is_Tarefa_Fechada = Convert.ToBoolean(_tarefa_fechada);
db.T_OsParceiro.Add(parceiro);
db.SaveChanges();
return parceiro;
}
}
The error is in Savechanges(); What I added was: _datafechamentoos
Looking at the error log I know the problem is in my entity. I just don’t know why you are making that mistake, because what was added, in my opinion, did nothing other than what already existed. Before everything worked, even the test was done by the Web Service with the partner consuming the WS or API(REST). The log asks me to see this: 'EntityValidationErrors'
, but I don’t know how to.
I don’t know if this is the problem, but when I put everything on the watch, and I opened each item, there in the Entry >> Entity, it shows the attributes of my entity, okay? Well, I have an Identity field called Elderly Partner, he should be with 11, because I max value Elderly Partner is 10 and there was 0. Well, I think at the time of Savechanges(), I think Identity should already be fired, right? That was the remark I made that I thought was different.
First of all, modify your
db.SaveChanges
following the script for that answer to see the errors: http://answall.com/questions/17644/como-correctr-o-entityvalidationerrors/17648#17648– Leonel Sanches da Silva
I could not make it work as you sent me, Gypsy. The base.Savechanges() gives error
– pnet
The idea is to fall inside the Exception so you can see the errors, using breakpoints and Watch windows.
– Leonel Sanches da Silva