LinqExtender 1.4 - Enhanced object tracking
Its been quite a while since I made any release of the toolkit. I basically, get into user requests, used it myself in LinqToFlickr project and came up with some new features and enhancements.
In my last post, I already mentioned about comment and photo update feature in LinqToFlickr (Athena) , where the update tracking is actually comes from this toolkit.
Book book = (from b in context where b.Id == 1 select b).Single(); // let's update a property book.ISBN = "1101"; // this will trigger the update. context.SubmitChanges();
Note that Book object is a simple class that inherits QueryObjectbase for making it query enable that looks like the following with no fancy tricks.
[OriginalEntityName("book")] class Book : QueryObjectBase { [LinqVisible]// makes the property visible to toolkit public string Author { get; set; } [LinqVisible, OriginalFieldName("Bk_Title")] public string Title { get; set; } [LinqVisible] public string ISBN { get; set; } ... ... }
So, during SumitChanges the toolkit will track for any changes that is made after adding or getting the item or list of items and call the Query<T>.UpdateItem
protected bool UpdateItem(Bucket item) { Bucket contains the updated property- value map //finally do a return , if true, then only the //collection will be updated or //it will revert back to the old one and raise an OnError event. return true/false; }
You just need to put the appropriate update logic in here. Bucket.Items contains the latest value after the user changes. Moreover, you can use bucket.Items.IsUnique or bucket.UniqueItems to track down the Identity property which is defined by UniqueIdentifierAttribute.
In addition to this , now we have another optional override Query<T>.GetItem : T . This is equivalent to the popular GetById in our database driven world.
Photo detail = (from p in context.Photos where photo.Id == 22212 && p.Size == PhotoSize.Medium).Single();
With this query from Athena (LinqToFlickr API), we can see that the query gets the single photo by an identity lookup and optionally it asks for medium sized photos only. Generally , we can combine it with IF-Else in the Query<T>.Process with generic search logic, but rather having two sets of logic we can also implement the GetById under GetItem override. The typical look of it
protected override T GetItem(Bucket item) { T singleObject = GetItThoughUniqueValue(...); return singleObject; }
Finally, AddItem, DeleteItem and UpdateItem overrides of Query<T> has now a return type bool instead of void . This forces the provider writer to return a bit status indicating success and failure of the operation. Optionally , with false status it raises a OnError event , which user can use to log the error.
There are few more updates with 1.4 release check all these out at www.codeplex.com/LinqExtender . Also, the features page gives a detailed list.