The documentation comes from the Markdown files in the source code, so is always up-to-date but available only in English. Enjoy!
Database is the main facade of Signum Engine for normal operations with entities, like saving, retrieving or deleting particular entities, or write complex queries to retrieving, update, delete or insert many entities at the same time.
Three things that make Database class different to many other ORM:
Connector.Override method.Entity objects, also you will find strongly-typed generic overloading. But what you are not going to find there are properties to deal specifically with some concrete entity. This way the business logic in your modules only depend on the common Database class, not a particular class representing your particular database, so they can be used in other projects.Administrator, and test all your queries and code.Let's start with an example.
Suppose you have a very simplistic UserEntity entity like this one:
[Serializable, EntityKind(EntityKind.Main, EntityData.Transactional)]
public class UserEntity : Entity
{
[UniqueIndex]
string userName;
public string UserName
{
get { return userName; }
set { Set(ref userName, value); }
}
string passwordHash;
public string PasswordHash
{
get { return passwordHash; }
set { Set(ref passwordHash, value); }
}
}Note: *In case you don't know why the field is named
passwordHashinstead of password click here.
And you need to be able to change user's password, it would be implemented like this:
private static void ChangePassword(string userName, string oldPasswordHash, string newPasswordHash)
{
using (Transaction tr = new Transaction())
{
UserEntity user = Database.Query<UserEntity>().Single(a => a.UserName == userName);
if (user.PasswordHash != oldPasswordHash)
throw new ApplicationException("Incorrect password");
user.PasswordHash = newPasswordHash;
user.Save();
tr.Commit();
}
}Looks easy, doesn't it?
This is what is actually happening:
Transaction. Every atomic operation exposed by Database class is implicitily transactional, but by explicitly surrounding it with a Transaction object we are just making the transaction bigger.Set method of the entity is called, so the entity becomes self modified.Database.Save extension method to save the entity. You could write Database.Save(user) instead if you find it more clear. Also, in this example we're saving a simple entity but it could have a whole graph of related entities if necessary.© Signum Software. All Rights Reserved.
Powered by Signum Framework