Last active
March 21, 2018 03:08
-
-
Save eschneider999/4d16e090d5876fb9cdcd6a25c8bd281e to your computer and use it in GitHub Desktop.
Symbiotic ORM Insert Update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void TestInsertUpdate() | |
{ | |
IDatabaseTypesFactory factory = new DatabaseTypesFactorySqlServer(); | |
// Intialize database connection string | |
factory.ConnectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\Dev\\FrozenElephant\\SymbioticORM\\SqlDatabase\\SymbioticTestLocal.mdf;Integrated Security=True;Connect Timeout=30"; | |
IObjectWriter writer = factory.CreateObjectWriter(); | |
//Should do an insert | |
ErrorItem er0 = new ErrorItem(); | |
er0.ItemDate = DateTime.Now; | |
er0.Text = "Test insert-update " + DateTime.Now.ToString(); | |
writer.InsertUpdate(er0); | |
//Should do an update | |
er0.Text = "Test insert-update 2 " + DateTime.Now.ToString(); | |
writer.InsertUpdate(er0); | |
} | |
// ErrorItem object below | |
// IObjectChangedSupport is implement to reduce updates, but is not required | |
using System; | |
using System.Diagnostics; | |
using FrozenElephant.Symbiotic; | |
[Serializable()] | |
[DatabaseTable("Errors")] | |
[DebuggerDisplay("ErrorItem: {m_Id} {m_ItemDate} {m_Text}")] | |
public class ErrorItem : IObjectChangedSupport { | |
private DateTime m_ItemDate = new DateTime(1950, 1, 1); | |
private string m_Text; | |
private long m_Id; | |
public ErrorItem() { | |
m_Isnew = true; | |
} | |
[DatabaseColumnAttribute("ErrorId", IsPrimaryKey = true, IsIdentityColumn = true)] | |
public long Id { | |
get { return m_Id; } | |
set { m_Id = value; } | |
} | |
[DatabaseColumnAttribute("Date")] | |
public DateTime ItemDate { | |
get { return m_ItemDate; } | |
set { | |
if (m_ItemDate.Equals(value) == false && m_Isnew == false) { | |
m_IsChanged = true; | |
} | |
m_ItemDate = value; | |
} | |
} | |
[DatabaseColumnAttribute("ErrorInfo")] | |
public string Text { | |
get { return m_Text; } | |
set { | |
if ((m_Text != null) && m_Text.Equals(value) == false && m_Isnew == false) { | |
m_IsChanged = true; | |
} | |
m_Text = value; | |
} | |
} | |
#region "IObjectChangedSupport implements" | |
private bool m_Isnew; | |
private bool m_IsChanged; | |
public bool IsChanged() { | |
return m_IsChanged; | |
} | |
public bool IsNew() { | |
return m_Isnew; | |
} | |
public void MarkAsOld() { | |
m_Isnew = false; | |
} | |
public void MarkAsUnchanged() { | |
m_IsChanged = false; | |
} | |
#endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment