I’m working on a sample project where I have three tables in play: user, company, and a “link” table that links users to companies. All three tables have a unique identifier (Oid) as the primary key. The “link” table has a column for the user’s Oid and a column for the company’s Oid. There’s a constraint that requires the user id to be in the user table and the company id to be in the company table when inserting a “link” record.
I log in my user account and fetch the Oid for the currently logged in user.
Then I create a new company record.
Then I create a new “link” record to connect that user to the newly created company.
When I call ApplyUpdates() an error is generated stating that Oid is not in the result set. However, if I call ApplyUpdates() after each insert everything works without a hitch.
Should I be able to insert both records then call ApplyUpdates() once?
This is not the only instance where I have such master/detail tables with constraints, foreign keys, etc.
I’m wanting to use the Briefcase mode for a mobile application and my concern is that records will be added to the briefcase then when I try to push the changes back up to the server then I’ll run into issues.
private RemoteTableQuery<dbo_Company> companies = null;
private RemoteTableQuery<dbo_BrechbuhlerUser> users = null;
public ObservableCollection<Item> Items { get; set; }
public Command LoadItemsCommand { get; set; }
async Task<bool> AddToDatabase(Item item)
{
if (companies == null)
return await Task.FromResult(false);
dbo_Company company = new dbo_Company();
company.id = Guid.NewGuid();
company.Name = item.Text;
company.DisplayName = item.Description;
company.IsActive = false;
module.DataAdapter.InsertRow<dbo_Company>(company);
module.DataAdapter.ApplyChanges(); // Error occurs if I remove this line...
dbo_CompanyCompanies_BrechbuhlerUserUsers link = new dbo_CompanyCompanies_BrechbuhlerUserUsers();
link.OID = Guid.NewGuid();
link.id = link.OID.ToString();
link.OptimisticLockField = 0;
link.Users = user.Oid;
link.Companies = company.id;
module.DataAdapter.InsertRow<dbo_CompanyCompanies_BrechbuhlerUserUsers>(link);
module.DataAdapter.ApplyChanges();
Trace.WriteLine(string.Format("{0} {1}", item.Text, item.Description));
Items.Add(item);
return await Task.FromResult(true);
}