Post by tjvrdev on Apr 3, 2020 16:38:30 GMT
It's inconsistent but sometimes I get a Constraint error for my class. I've tried to remove all the members but the primary key but now it's still giving me the same error. The class is wrapped in a namespace and looks like this.
[PrimaryKey]
public string EntryID { get; set; }
Any ideas/feedback on how I can further troubleshoot the issue?
[edit]
I think i've figured out the issue, I have 2 constructors in the class, one default & the other that loads the class fields through constructor parameters. When I moved the default constructor logic to be the first constructor it seemed to be fixed. In my code, im loading test data into the db in the form of a for loop. I'm creating a list of data then looping through each one to insert into the db. The first entry inserts fine but the 2nd entry throws constraint error. Do you think it's because i'm iterating through a for loop and its using insert calls to rapidly?
[edit]
The problem was I was using the same EntryID for the 2nd insert. What i'm trying to accomplish is loading stats for a machine and using the machines ID as the primary key. The stats represent the stats of days of the week but the machines ID is static. I use the machinesID as the key so its easy to find the stats for that machine. But what it looks like is the ID, needs to be different for each insert. So I can find the machine using a new index like machineID and build out logic to generate a primary key for each time that machines stats are being inserted to the table.
[edit]
If any readers need to find a way to generate a unique id, it looks like this logic works well:
string DBEntryID = Guid.NewGuid().ToString("N");
[PrimaryKey]
public string EntryID { get; set; }
Any ideas/feedback on how I can further troubleshoot the issue?
[edit]
I think i've figured out the issue, I have 2 constructors in the class, one default & the other that loads the class fields through constructor parameters. When I moved the default constructor logic to be the first constructor it seemed to be fixed. In my code, im loading test data into the db in the form of a for loop. I'm creating a list of data then looping through each one to insert into the db. The first entry inserts fine but the 2nd entry throws constraint error. Do you think it's because i'm iterating through a for loop and its using insert calls to rapidly?
[edit]
The problem was I was using the same EntryID for the 2nd insert. What i'm trying to accomplish is loading stats for a machine and using the machines ID as the primary key. The stats represent the stats of days of the week but the machines ID is static. I use the machinesID as the key so its easy to find the stats for that machine. But what it looks like is the ID, needs to be different for each insert. So I can find the machine using a new index like machineID and build out logic to generate a primary key for each time that machines stats are being inserted to the table.
[edit]
If any readers need to find a way to generate a unique id, it looks like this logic works well:
string DBEntryID = Guid.NewGuid().ToString("N");