0

I have a form that allows user to update and also create new entries to database, I am able to update but not create. The following is dal

if (actionrequired == Crud.Modify)
{
                    t_ProvisionSetup setupToBeChanged = (from p in Entities.t_ProvisionSetup
                                                         where p.ProvisionSetupId == provision.ProvisionSetupId
                                                         select p).Single();
                    setupToBeChanged.ModifiedOn = DateTime.UtcNow;
                    setupToBeChanged.ModifiedBy = userId;
                    setupToBeChanged = MapSetupToEntity(provision, setupToBeChanged);
                    Entities.SaveChanges();
                    setupid = setupToBeChanged.ProvisionSetupId;
}

if (actionrequired == Crud.Add)
{
                    t_ProvisionSetup setupToBeChanged = new t_ProvisionSetup();
                    setupToBeChanged = MapSetupToEntity(provision, setupToBeChanged);
                    setupToBeChanged.ModifiedBy = userId;
                    setupToBeChanged.ModifiedOn = DateTime.UtcNow;
                    setupToBeChanged.CreatedBy = userId;
                    setupToBeChanged.CreatedOn = DateTime.UtcNow;

                    Entities.SaveChanges();
                    setupid = setupToBeChanged.ProvisionSetupId;
}

It runs fine no errors but won't create new record.

1 Answer 1

2

Possibly you need something like this?

Entities.t_ProvisionSetup.Add(setupToBeChanged);

before calling Entities.SaveChanges().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.