Home
Options

Problem with nested insert

I am having trouble using nested inserts. I have a database with a number of tables, but this particular query only uses two of them, Job and Color. Each Job entry can have one or more Color entries associated with it. I'm using the IQ Driver, as this is a MySQL database.

The driver appears to set up the navigation properties properly, but they don't appear to be working in my case. I've seen a number of similar examples on various forums, and it seems that I am following the same basic flow, yet my inserts are not working.

In this example, I am trying to create a single Job entry with 4 associated Colors. As you can see, the "job" instance shows the 4 colors in its "Color" property, but after submitting changes, the colors are not inserted into the database.

I have tried moving the Job.InsertOnSubmit() line after the creation of the Color entries, but that doesn't change anything.

What am I missing here?

code:

void Main()
{
    var job = new Job {
        CustomerName = "Sisco Foods",
        JobName = "Purple Storm",
        ProductionNumber = "123456-7",
        TotalMeterage = 13000.0f,
        RepeatLength = 0.75f,
        WebWidth = 1.25f,
        Status = 0
    };
    Job.InsertOnSubmit(job);

    var color = new Color {
        OriginalColorName = "Candy Apple Red",
        DisplaySequence = 0,
        AreaCoverage = 25.4m,
        Job = job,
        Status = 0
    };
    job.Color.Add(color);
    color = new Color
    {
        OriginalColorName = "Lime Green",
        DisplaySequence = 1,
        AreaCoverage = 53.4m,
        Job = job,
        Status = 0
    };
    job.Color.Add(color);
    color = new Color
    {
        OriginalColorName = "Lemon Yellow",
        DisplaySequence = 2,
        AreaCoverage = 29.6m,
        Job = job,
        Status = 0
    };
    job.Color.Add(color);
    color = new Color
    {
        OriginalColorName = "Orange Orange",
        DisplaySequence = 3,
        AreaCoverage = 85.3m,
        Job = job,
        Status = 0
    };
    job.Color.Add(color);

    SubmitChanges();
    job.Dump();
    Job.Dump();
    Color.Dump();
}

Results:

Comments

Sign In or Register to comment.