Created
March 6, 2014 13:28
-
-
Save warpech/9389676 to your computer and use it in GitHub Desktop.
Object equality test
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
using System; | |
using Starcounter; | |
[Database] | |
public class Panda | |
{ | |
public string Name; | |
} | |
class Program | |
{ | |
static void Main() | |
{ | |
Panda harry0 = Db.SQL<Panda>("SELECT p FROM Panda p WHERE Name = ?", "Harry").First; | |
if (harry0 == null) | |
{ | |
Db.Transaction(() => | |
{ | |
new Panda() | |
{ | |
Name = "Harry" | |
}; | |
}); | |
} | |
Panda harry1 = Db.SQL<Panda>("SELECT p FROM Panda p WHERE Name = ?", "Harry").First; | |
Panda harry2 = Db.SQL<Panda>("SELECT p FROM Panda p WHERE Name = ?", "Harry").First; | |
if (harry1 == harry2) | |
{ | |
Console.WriteLine("The same object"); | |
} | |
else | |
{ | |
Console.WriteLine("Not the same object"); | |
} | |
Db.Transaction(() => | |
{ | |
Db.SlowSQL("DELETE FROM Panda"); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment