Using database first entity framework. Inserting records into one of my tables, no problem at all. Then I discovered under certain, very rare, circumstances, I was getting duplicate records, which are actually ok. So my plan to deal with those was to create an identical table, catch the exception, put the duplicate in the identical table and examine it at some later stage.
However, I naively thought as they were identical tables, I could just insert the object I have already created into the other "error" table, which obviously I can't do ("cannot convert from 'original_class' to 'new_class'"), which I understand.
So is there a better way to do what I am trying to achieve, or is there a simple way to convert my 'original_class' to my 'new_class' as they are absolutely identical?
***Edit Thought it may be beneficial to add some code for clarity (not my actual code, just a representation of what I am trying to achieve)
My Transaction Class
public partial class Tran
{
public string tranDescription
}
My Transaction Error Class
public partial class TranError
{
public string tranDescription
}
How I am trying to process the error
using(var db = new tranEntities())
{
Tran t = new Tran();
t.tranDescription = @"Some Description";
try
{
db.Trans.Add(t);
}
catch (System.Data.Entity.Infrastructure.DbUpdateException)
{
db.TransError.Add(t);
}
}
I just typed that on the fly, so forgive any typos, I think you get the idea.