This question is locked. New answers and comments are not allowed.
Hello!
I am currently evaluating OpenAccess for use for new module within an application that currently does not use any ORM. My version is Q1 2013 (version 2013.1.219.3), as stated by Samples Kit.
As the most of the application logic is located within stored procedures, I am trying to accomplish the following when persisting data:
BEGIN TRAN
EXEC BeforeSaveChangesProcedure
{Saving changes}
EXEC AfterSaveChangesProcedure
COMMIT
(i.e. executing custom procedures along with data persistence in the same transaction).
I saw that SaveChanges begins and ends a transaction by itself and I do not know if OpenAccess allows this scenario. To easily understand the issue, I have created a small Windows Forms App - I will paste the relevant code:
public partial class MainForm : Form
{
Document theDocument = null;
DocumentModel context = new DocumentModel();
private const string connectionId = "TestConnection";
public MainForm()
{
InitializeComponent();
LoadData();
BindControls();
}
private void LoadData()
{
int documentId = 1;
theDocument = context.Documents.FirstOrDefault<Document>(ent => ent.DocumentId == documentId);
}
private void BindControls()
{
txtDocumentNumber.DataBindings.Clear();
txtDocumentNumber.DataBindings.Add(new Binding("Text", theDocument, "DocumentNumber"));
dtDocumentDate.DataBindings.Clear();
dtDocumentDate.DataBindings.Add(new Binding("Value", theDocument, "DocumentDate"));
txtDocumentAmount.DataBindings.Clear();
txtDocumentAmount.DataBindings.Add(new Binding("Text", theDocument, "DocumentValue", true));
}
private void btnSaveData_Click(object sender, EventArgs e)
{
try
{
// context.Connection.BeginTransaction(); // does not work for bound connections
context.SaveChanges();
}
catch (Exception)
{
}
}
}
Any idea how this can be done? Thank you,
Alex D.
I am currently evaluating OpenAccess for use for new module within an application that currently does not use any ORM. My version is Q1 2013 (version 2013.1.219.3), as stated by Samples Kit.
As the most of the application logic is located within stored procedures, I am trying to accomplish the following when persisting data:
BEGIN TRAN
EXEC BeforeSaveChangesProcedure
{Saving changes}
EXEC AfterSaveChangesProcedure
COMMIT
(i.e. executing custom procedures along with data persistence in the same transaction).
I saw that SaveChanges begins and ends a transaction by itself and I do not know if OpenAccess allows this scenario. To easily understand the issue, I have created a small Windows Forms App - I will paste the relevant code:
public partial class MainForm : Form
{
Document theDocument = null;
DocumentModel context = new DocumentModel();
private const string connectionId = "TestConnection";
public MainForm()
{
InitializeComponent();
LoadData();
BindControls();
}
private void LoadData()
{
int documentId = 1;
theDocument = context.Documents.FirstOrDefault<Document>(ent => ent.DocumentId == documentId);
}
private void BindControls()
{
txtDocumentNumber.DataBindings.Clear();
txtDocumentNumber.DataBindings.Add(new Binding("Text", theDocument, "DocumentNumber"));
dtDocumentDate.DataBindings.Clear();
dtDocumentDate.DataBindings.Add(new Binding("Value", theDocument, "DocumentDate"));
txtDocumentAmount.DataBindings.Clear();
txtDocumentAmount.DataBindings.Add(new Binding("Text", theDocument, "DocumentValue", true));
}
private void btnSaveData_Click(object sender, EventArgs e)
{
try
{
// context.Connection.BeginTransaction(); // does not work for bound connections
context.SaveChanges();
}
catch (Exception)
{
}
}
}
Any idea how this can be done? Thank you,
Alex D.