Object cannot be converted from Dbnull to other types = Entity Framework Core to Firebird

Asked

Viewed 108 times

-2

I have the following table that has the fields(ID, numeronota, clienteID, dataemissao, totalnota, desconto, troco).

In this table there are fields that is null, example the change and discount, I’m looking for this table using EF Core. In the entity this so:

[key]  
[Colunm("ID")]  
public int ID {get; set;}  
[Colunm("NUMERONOTA")]  
public int Numeronota{get;set}  
[ForeignKey("ID")]  
public Cliente ClienteID{get; set;}  
[Colunm("DATAEMISSAO")]  
public DateTime Dataemissao{get;set;}  
[Colunm("TOTALNOTA")]  
public double Totalnota{get;set;}  
[Colunm("DESCONTO")]  
public double? Desconto{get;set;}  
[Colunm("TROCO")]  
public double? Troco{get; set;}  

In the Context class

public DbSet<Cliente> Clientes { get; set; }  
public DbSet<Nota> Notas { get; set; }  

I’m calling it that

using ( var contexto = new EntidadesContext()) {  
                contexto.LogSQLToConsole();                  
                foreach (var nota in contexto.Nota )  
                {                    

                }  
            }  

If I look for the client table with all fields filled in comes normal, only the note table of the error.

1 answer

0

You need to declare the properties that may receive null values in your entity, as you did with some of them. And you need to check the same thing in the table and in the entity Client.

[key]  
[Colunm("ID")]  
public int ID {get; set;}  
[Colunm("NUMERONOTA")]  
public int? Numeronota{get;set}  
[ForeignKey("ID")]  
public Cliente ClienteID{get; set;}  
[Colunm("DATAEMISSAO")]  
public DateTime? Dataemissao{get;set;}  
[Colunm("TOTALNOTA")]  
public double? Totalnota{get;set;}  
[Colunm("DESCONTO")]  
public double? Desconto{get;set;}  
[Colunm("TROCO")]  
public double? Troco{get; set;}  
  • Thanks for answering, so I did it, but still the error continues, can not pull the fields that are null in the database, using pure SQL I can do the search using isDBNull, but with Entity Framework I can not do it yet.

  • You reviewed the client class as well?

  • Thank you very much, I had to put all the fields of all entities as ? , now passed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.