Skip to content

Instantly share code, notes, and snippets.

@eschneider999
Last active September 25, 2016 20:11
Show Gist options
  • Save eschneider999/7822cb93e3c47980e6243175b1260188 to your computer and use it in GitHub Desktop.
Save eschneider999/7822cb93e3c47980e6243175b1260188 to your computer and use it in GitHub Desktop.
Symbiotic ORM Core Save data
public void TestCreate()
{
private 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";
//Create the object to save
ErrorItem er = new ErrorItem();
er.ItemDate = DateTime.Now;
er.Text = text;
//write it to the database
IObjectWriter writer = factory.CreateObjectWriter();
writer.Create(er);
//Check that it is in the DB
IObjectLoader loader = factory.CreateObjectLoader();
ErrorItem s = loader.ObtainItem<ErrorItem>(er.Id);
if (s == null)
{
Assert.Fail();
}
}
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