I am trying to figure out which column, or columns, is tripping the error below. Something changed about the incoming data, fed by a 3rd party service and it is now causing failures when I try to save it to SQL.
Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.SqlClient.SqlException: Arithmetic overflow error converting numeric to data type numeric. The statement has been terminated.
A very simple flow:
- Read 3rd party API as JSON
- Use newtonsoft to convert directly to EF data model class
- Add record(s) to DB then save.
Data structure is defined as:
[JsonObject(MemberSerialization.OptIn)]
public class RatDbAttributes
{
[JsonProperty]
[StringLength(50)]
public string block_chain { get; set; } // varchar(50)
[JsonProperty]
[StringLength(50)]
public string block_reduction { get; set; } // varchar(50)
[JsonProperty]
[StringLength(50)]
public string block_reward { get; set; } // varchar(50)
[JsonProperty]
public double block_time { get; set; } // decimal(28,6)
[JsonProperty]
[StringLength(100)]
public string consensus_method { get; set; } // varchar(100)
[JsonProperty]
public decimal decimals { get; set; } // decimal(28,6)
[JsonProperty]
[StringLength(50)]
public string difficulty_retarget { get; set; } // varchar(50)
[JsonProperty]
[StringLength(200)]
public string genesis_address { get; set; } // varchar(200)
[JsonProperty]
[StringLength(100)]
public string hash_algorithm { get; set; } // varchar(100)
[JsonProperty]
[StringLength(50)]
public string mineable { get; set; } // varchar(50)
[JsonProperty]
public long p2p_port { get; set; } // bigint
[JsonProperty]
public long rpc_port { get; set; } // bigint
[JsonProperty]
[StringLength(200)]
public string token_role { get; set; } // varchar(200)
[JsonProperty]
public decimal @float { get; set; } // decimal(28,6)
[JsonProperty]
public decimal minted { get; set; } // decimal(28,6)
[JsonProperty]
public decimal total_supply { get; set; } // decimal(28,6)
[JsonProperty]
public decimal max_supply { get; set; } // decimal(28,6)
[JsonProperty]
[StringLength(133)]
public string wallet { get; set; } // varchar(133)
[JsonProperty]
[NotMapped]
public double genesis_timestamp { get; set; } // see below
[JsonIgnore]
public DateTime Genesis_TimeStamp { get { return genesis_timestamp.ToDateTime(); } set { genesis_timestamp = value.ToEpoch(); } }
// Foregin Key Relationship (1-to-1) and Primary Key
[JsonIgnore]
public long TokenMasterId { get; set; }
[JsonIgnore]
[ForeignKey("TokenMasterId")]
public RatDbTokenMaster TokenMaster { get; set; } //foreign key to Parent
}
I've double checked the genesis_timestamp
and that is not the problem (converting double to datetime).
Sample incoming failing JSON:
{"block_chain":""
,"block_reduction":""
,"block_reward":"0"
,"block_time":0.0
,"consensus_method":""
,"decimals":0.0
,"difficulty_retarget":""
,"genesis_address":""
,"hash_algorithm":""
,"mineable":"False"
,"p2p_port":0
,"rpc_port":0
,"token_role":""
,"float":0.0
,"minted":0.0
,"total_supply":0.0
,"max_supply":0.0
,"wallet":""
,"genesis_timestamp":0.0
}
[StringLength]
attribs to see if a string length error would popup. I've run it both ways. The bigger picture, all 9 tables, except this one, run flawlessly. – Keith Barrows May 6 '19 at 18:01