Olá Daniel, como vai?
Seguem os dados:
- DDL do banco de dados (MySql):
CREATE TABLE senhas (
id int(11) NOT NULL AUTO_INCREMENT,
codcoligada int(11) NOT NULL,
codfilial int(11) NOT NULL,
codsetor int(11) NOT NULL,
senhaespecial int(11) NOT NULL,
senha int(11) NOT NULL,
sigla varchar(10) DEFAULT NULL,
guiche varchar(6) NOT NULL,
datasenha datetime(6) NOT NULL,
datachamada datetime(6) DEFAULT NULL,
codatendente int(11) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
namespace Senha_Usuario
{
public class SenhaContext : DbContext
{
public DbSet Senhas { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseMySql("Server=localhost;User Id=root;Password=root;Database=senha");
}
}
}
INSERT INTO senha.senhas (codcoligada, codfilial, codsetor, senhaespecial, senha, sigla, guiche, datasenha) VALUES ('1', '7', '1', '0', '12', 'SECR', '01', '2019-08-12 21:00:23') --> Perceba que os campos datachamada e codatendente não foram inclusos valores
- Ao executar o programa ocorre o erro abaixo, mas se eu incluir valor nos dois campos nulos o programa funciona corretamente - será que é um problema com o Pomelo ou com o EF?:
System.InvalidCastException: 'Conversão especificada não é válida.'
System.InvalidCastException
HResult=0x80004002
Message=Conversão especificada não é válida.
Source=MySqlConnector
StackTrace:
em MySqlConnector.Core.Row.GetInt32(Int32 ordinal) em C:\projects\mysqlconnector\src\MySqlConnector\Core\Row.cs:linha 177
em MySql.Data.MySqlClient.MySqlDataReader.GetInt32(Int32 ordinal) em C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:linha 181
em Microsoft.EntityFrameworkCore.Storage.Internal.TypedRelationalValueBufferFactory.Create(DbDataReader dataReader)
em Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer)
em Pomelo.EntityFrameworkCore.MySql.Storage.Internal.MySqlExecutionStrategy.Execute[TState,TResult](TState state, Func3 operation, Func3 verifySucceeded)
em Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.Enumerator.MoveNext()
em Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<TrackEntities>d__172.MoveNext()
em Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor1.EnumeratorExceptionInterceptor.MoveNext()
em System.Collections.Generic.List1..ctor(IEnumerable1 collection)
em System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
em SenhaUsuario.frmSenhaUsuario.btChamarLista_Click(Object sender, EventArgs e) em C:\Projetos\VS2017\Senha\Senha_Usuario\frmChamadaSenha.cs:linha 57
em System.Windows.Forms.Control.OnClick(EventArgs e)
em System.Windows.Forms.Button.OnClick(EventArgs e)
em System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
em System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
em System.Windows.Forms.Control.WndProc(Message& m)
em System.Windows.Forms.ButtonBase.WndProc(Message& m)
em System.Windows.Forms.Button.WndProc(Message& m)
em System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
em System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
em System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
em System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
em System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
em System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
em System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
em System.Windows.Forms.Application.Run(Form mainForm)
em Senha_Usuario.Program.Main() em C:\Projetos\VS2017\Senha\Senha_Usuario\Program.cs:linha 19