I have two tables:
**Complaint**
-Id
-CreatedBy
-CreatedDate
....
**Solution**
-Id
-ComplaintId
Sometimes a complaint has an instant solution, which means that when it is created, a solution is also created. The database is Oracle, and to insert a new record into the database, I set the StoredGeneratePattern to Identity and use a trigger to insert the sequence value.
here my code:
using (var context = new Entities())
{
var complaint = new Complaint
{
Title = TitleTextBox.Text.Trim(),
CreatedBy = CurrentUser.UserID,
Description = DescriptionTextBox.Text.Trim(),
ServiceId = Convert.ToDecimal(ddlService2.Value),
Contact = ContactTextBox.Text.Trim(),
CreatedDate = DateTime.Now,
Customer = txtUserName.Text.Trim(),
ResellerId = CurrentUser.ResellerID,
Status = ComplaintStatus.GetStatusCode("New complaint")
};
if (CompletedCheckBox.Checked)
{
complaint.Status = ComplaintStatus.GetStatusCode("Completed");
var solution = new Solution
{
CreatedBy = CurrentUser.UserID,
CreatedDate = DateTime.Now,
SolutionDesc = DescriptionTextBox.Text,
ComplaintId = complaint.Id
};
context.Solutions.AddObject(solution);
}
context.Complaints.AddObject(complaint);
if(context.SaveChanges() > 0)
{
ResetFrom();
return true;
}
}
the problem is that I cannot get the identifier of the newly created complaint in order to set the field in the solution. How can i do this?
Thank.
source
share