Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent phantom inserts of empty entities #22

Open
FransBouma opened this issue Jan 16, 2015 · 0 comments
Open

Prevent phantom inserts of empty entities #22

FransBouma opened this issue Jan 16, 2015 · 0 comments

Comments

@FransBouma
Copy link
Owner

This test fails

[Test]
public void PhantomInsertPreventionTest()
{
    var newCustomer = new Customer();
    var ba = new Address();
    var va = new Address();
    newCustomer.VisitingAddress = va;
    newCustomer.BillingAddress = ba;

    // as everything is empty, and Address isn't saved because it's not dirty, customer shouldn't be saved as well.
    using(var ctx = GetContext())
    {
        ctx.Customers.InsertOnSubmit(newCustomer);
        ctx.SubmitChanges();
        Assert.AreEqual(0, ba.AddressId);
        Assert.AreEqual(0, va.AddressId);
    }
}

because Linq to Sql happily inserts Address, while it's not dirty and has nonnullable fields. No save should occur at all, as there are only empty entities to persist. Preventing these 'phantom' inserts will avoid the user running into either empty rows (because there were nullable fields so the persist succeeded), or have to check up front whether a save is necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant