Example 1 : Using SqlServerStorage
var storage = new SqlServerStorage {
ConnectionString=”Server=(local);DataBase=MyDB;”};
using (var t=storage.BeginTransaction()) {
var person = storage.Get<Person>(5);
storage.Remove(person);
t.Commit();
}
Example 2 : Queries
var storage = new SqlServerStorage {
ConnectionString=”Server=(local);DataBase=MyDB;”};
using (var t= storage.BeginTransaction()) {
var person = storage.Query<Person>().Where(p=>p.ID=5);
storage.Remove(person);
t.Commit();}
These samples work almost the same way as DataObjects usually do, just syntax is a bit different. Offline storage is more interesting. Offline storage deals with object the same way as Svn works with files. One can get objects which are in consistent state with each other but the whole storage state is not guaranteed to be in a consistent state. For example, that is how objects can be loaded
Example 3 : Using OfflineStorage
var storage = new SqlServerStorage {
ConnectionString=”Server=(local);DataBase=MyDB;”};
var offlineStorage = new OfflineStorage(storage);
using (offlineStorage.BeginTransaction()) { // Real transaction was created
var person = offlineStorage.Get<Person>(4);
var book = offlineStorage.Get<Book>(5);
}
var person = offlineStorage.Get<Person>(6);
Person #4 and Book #5 are guaranteed to be in a consistent state but Person #4 and Person #6 are not. Offline storage never updates real data, one should call “Commit” manually.
Example 4: OfflineStorage changes
var storage = new SqlServerStorage {
ConnectionString=”Server=(local);DataBase=MyDB;”};
var offlineStorage = new OfflineStorage(storage);
var person = offlineStorage.Get<Person>(6);
person.Name = “Alex”;
offlineStorage.SaveChanges();
Of course, SaveChanges call leads to to creation of new Transaction at real storage.
Another interesting moment is transferring data over network. It is achieved using special storage called StorageProxy. There is an example of using StorageProxy:
var storage = new StorageProxy(“tcp:/myServer.com:5040”);
using (storage.BeginTransaction()) {
var p = storage.Get<Person>(5);
storage.Remove(p);}
So one can make n-tier application just plugging proxies one to another. I could continue examples, but for one post it seems to enough.

It seems, at least for me, that this could be mostly a n-tier Storage API rather than ORM API. Personally, I don't see any ORM-related tasks in the examples.
ОтветитьУдалить