Signum Framework Logo
"Open framework that encourages convention over configuration, using C# code,
not XML files, to model at the right level of abstraction and achieve deadlines.
...but also has a full Linq provider, and syncs the schema for you!"
Login
RSS

Search

»



Main
Index
Map
Videos
Download
Source code
Tutorials
Forum
FAQ



Image



PoweredBy

Introduction

Database class has a lot of overloading for retrieving single entities or a list of all the entities of a given type, the entities themselves or just Lazy objects, in a reusable weak-typed or in a strong-typed way using generics.

But probably, the most flexible way of retrieving some entities is using the integration of Database Linq queries with the retriever.

Finally, we will see how the Retriever actually works, just in case you are interested.

Retrieve Overloads

//Simple IdentifiableEntity retrieving
public static IdentifiableEntity Retrieve(Type type, int id) // Weak-Typed, for reusable components
public static T Retrieve<T>(int id) where T : IdentifiableEntity // Strong-Typed, for specific business logic

//Retrieving from Lazy objects. Fatten the lazy with the referenced entity. Returns this entity. public static IdentifiableEntity Retrieve(Lazy lazy) // Weak-Typed public static T Retrieve<T>(this Lazy<T> lazy) where T : class, IIdentifiable // Strong-Typed. Extension method!

//Retrieving from Lazy objects. Returns the referenced entity without storing it inside of the lazy. public static IdentifiableEntity RetrieveAndForget(Lazy lazy) // Weak-Typed public static T RetrieveAndForget<T>(this Lazy<T> lazy) where T : class, IIdentifiable // Strong-Typed. Extension method!

//Retrieve all entities of a given type (maybe very costly!) public static List<IdentifiableEntity> RetrieveAll(Type type) //Weak-Typed public static List<T> RetrieveAll<T>() //Strong-Typed

//Retrieve all entities as Lazy objects public static List<Lazy> RetrieveAllLazy(Type type) //Weak-Typed public static List<Lazy<T>> RetrieveAllLazy<T>() //Strong-Typed

//Retrieve entities given a list of ID's public static List<IdentifiableEntity> RetrieveList(Type type, List<int> ids) //Weak-Typed public static List<T> RetrieveList<T>(List<int> ids) //Strong-Typed

//Retrieve lazy objects given a list of ID's public static List<Lazy> RetrieveListLazy(Type type, List<int> ids) //Weak-Typed public static List<Lazy<T>> RetrieveListLazy<T>(List<int> ids) //Strong-Typed

Just after an entity is Retrieved, PostRetrieving method is called on it, so you can run whatever code you want. i.e. Assigning calculated values that are not stored in the database.

Note: Don't expect any of these methods to return null when the entity is not found. Instead they will throw an exception. If you want to test for the existance of an entity use Database.Exist method (weak and strongly typed). Know the reasons

Preserving Object Identity

In RDBMS, identity of rows is kept by the table they belong, and the almost-mandatory Identity column. If you have an identity column (and Signum Framework has one on every entity) there's no duplication of rows and finding a row is easy.

In object oriented languages, on the other hand, identity of objects is kept by the actual position on the heap they are placed. Two objects could be equal, but they are the same only if they are physically located in the same place in the heap. In C#, identity equality is tested using == operator or, if someone has overloaded it, object.ReferenceEquals.

To integrate the two worlds, its necessary to have a data structure that allows RDBMS identity behaviour in some scope of your code. Signum Engines solves that using ObjectCache class

Creative Commons License Signum Framework Site by Signum Software is licensed under a Creative Commons Attribution 3.0 License.
Powered by ScrewTurn Wiki version 3.0.5.600.