Rapid Repository is a Windows Phone 7 Database and Silverlight Isolated Storage Database.
- Release Overview
- Creating and saving entities
- Create, read, update and delete operations
- Querying with views and filters
- File Helper
- Examining Operation Requests
Creating and saving entities to the Windows 7 Phone is really simple when using the Rapid Repository.
For the following examples, my entity is called Player which among it’s properties contains a list of entities called GameScore.
As you can see, the Player class is the root entity or root aggregate, you will notice that it implement the IRapidEntity interface.
This interface enforces the implementation of a Guid Id property.
The following example shows how to save an entity to the database.
There is no setup at all, the following code is all you need to save a valid entity.
As you can see, once the player is created, a repository is created, the player is passed to the Add method and finally SaveChanges() is called on the current context.
The newPlayer instance passed in will now have it’s Id property populated (Do not change this Id).
The reason you call SaveChanges() is because when Add is called on the repository, it is just creating a request to save the entity, it is not actually saved until SaveChanges() is called.
Simple Example with Pre-Populated Id
Similar to the previous example, if for any reason you need to create your own Id rather than have the framework create it, you simple set the Id property before SaveChanges() is called on the context.
If you want to add extra functionality such as logging or you want to hide away the call to Savechanges() on the context, you can derive from RapidRepository<>, all the relevant methods can be overridden.
Now the above SavePlayer() method looks like the following:
That’s about it for saving entities, the next post will cover all of the Create, Read, Update and Delete functionality.
I hope you find this useful.