Click here to Skip to main content
15,893,588 members
Articles / Programming Languages / XML

ComponentOne for Entity Framework–Surprised Me

Rate me:
Please Sign up or sign in to vote.
4.00/5 (3 votes)
7 Aug 2012CPOL5 min read 12K   3   1
ComponentOne Studio for Entity Framework impressions.

A little while back I saw an email asking for someone familiar with Entity Framework to review a piece of Entity Framework tooling. I figured why not, since I had met some guys from ComponentOne at Dallas TechFest last year when they sponsored. It turned out to be ComponentOne Studio for Entity Framework.

Out of the Box – First Impressions

The tooling is fairly nice, but the real piece that hit me out of the box was the examples. It was like walking into to the kitchen and having dinner half way there for you. The samples turned out to be a great way to get started with the tools.

clip_image001[3]

The samples give some detailed descriptions of what is contained and then pop you right into a Visual Studio solution to start hacking. As a code junky this was a big plus for me.

In the Solution – References… oh my

I am kind of picky on things, and a bunch of references is normally one of those things, so I have to ding the ComponentOne guys on this. I had to bring in 4 references to my WPF project to get things up and running clip_image002[3]. I know that for most this won’t matter at all, but is one base reference to much to ask for? (Ok, off my soap box now.) More realistically (and less soap box) the need for several references makes sense. Different platforms/technologies need different reference chains. If you just want the LiveLinq awesomeness you don’t need the whole framework which is nice. I guess I will have to accept that the world doesn’t fit into my nice soap box.

clip_image003[3]

In the Code – Simple and powerful

Once I was in the code there were a couple of additions to my normal LINQ usage that piqued my interest: AsDynamic and AsLive. These two pieces seem to solve an issue that I have struggled with finding a good clean way of doing with little code.

I normally bind my grids and such to a ViewModel that holds observable collections under the hood and then take that and manually write the modifications to a queryable. This seemed to be redundant a lot of the time. That is where this came in for me. AsLive gives me an IObservableCollection directly from my lambda statement. I thought this was pretty sexy, but AsDynamic took it one step further by doing this on an anonymous projection. The only limiting factor here is it had to be used on the EntityCollection, or ICollection, which means we have to make sure to return ICollections. If we return EntityCollection it costs too much architecturally. There is one more, "HEY, that is cool feature hidden below."

clip_image004[3]

Did you notice the ADO and XML extensions? IObservable from a DataTable or XDoc/XElement!? Nice.

Transactions, UI, and rollback – NO WAY, Seriously?!

This one blew my socks off! Check this out.

C#
// All changes in this window are made in the scope of this client transaction.   
ClientTransaction _transaction;  

public OrderWindow(Order order, ClientTransaction transaction)   
{    
InitializeComponent();    
_transaction = transaction; 

// Create a proxy for the order that automatically opens the transaction scope   
// each time a value is assigned to a property; and use it for data binding.    
DataContext = transaction.ScopeDataContext(order);  

// Define a live view of order details.   
var orderDetailsView = from od in order.Order_Details.AsLive()    
select new OrderDetailsInfo    
{    
OrderID = od.OrderID,    
ProductID = od.ProductID,    
UnitPrice = od.UnitPrice,    
Discount = od.Discount,    
Quantity = od.Quantity    
};    
// All changes in this view are made in the transaction scope.    
orderDetailsView.SetTransaction(_transaction);    
orderDetailsGrid.ItemsSource = orderDetailsView;    
}

Yeah, that is pure win, with a side of awesome! [LL1] I have been working on a highly transacted application for the past 9 months and this would have saved SOOO much time. The only concern I have is that with this if you are also talking to something like WCF or another database you will need to setup DTC, but you would have had to do that any way for client transactions like this. This piece along with the integrated feel of Undo/Rollback makes the UI programming hurt less.

// Initialize the client transaction.   
// Specify that all changes to _ordersView are automatically considered changes made in the scope of this transaction.    
_transaction = _cache.CreateTransaction();    
_ordersView.SetTransaction(_transaction);

// Enable/disable the Undo button when the _transaction.HasChanges property value changes.   
_transaction.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(transaction_PropertyChanged);    
buttonUndo.IsEnabled = false;

if (_transaction.HasChanges)   
{    
// Ask the user whether they will save or cancel the changes made by this control.    
switch (MessageBox.Show("Do you want to save changes?", "", MessageBoxButton.YesNoCancel, MessageBoxImage.Question))    
{    
case MessageBoxResult.Yes:    
_transaction.Commit();    
break;    
case MessageBoxResult.No:    
_transaction.Rollback();    
break;    
case MessageBoxResult.Cancel:    
return;    
}    
}    
// Raise the CloseRequested event, so MainWindow removes the tab page with this control.    
CloseRequested(this, EventArgs.Empty);    
}

Client Side Cache – Not sure yet

A lot of what I saw when using ComponentOne Studio for Entity Framework tools used what they tag as “Smart Client-side Caching”. This piece is great in concept and in practice, but seemed to get a bit hairy when you want to work outside of the normal caching paradigm. This was just a chunk more code to have to manage to get around the cache in a targeted manner (for example a refresh on a cached object without dumping cache).

Virtual Mode – The art of well implemented low hanging fruit

Virtual Mode was a treat. The implementation of low hanging fruit always pleases me, but this was better. I have had to implement paging and async scrolling all over the place in the recent months because our users want massive data and they want responsiveness. ComponentOne nailed this one. The Virtual Mode is a simple Boolean property that turns on an async fetch of data on scroll! No more having to implement async paging myself!

This was just … nice.

General Overview – There is a lot of great here

I may be biased by working in a rather complex WPF UI for the last 9 months, but this thing rocks. I am not a huge fan of control suites, which is why I avoided their controls and just dealt with looking at the code. They offer those, but I think the biggest gains are in the LiveLINQ libraries, and their WPF extensions. This could have saved man weeks for my current client. The UI integration was simple, straight forward, and it handled transactions beautifully. I have to say I went into this rather skeptical, but when I got into the code ComponentOne has taken away a lot of the redundant pain that comes from integrating Entity Framework and a UI.

The only downside that I had was that the Highway.Data Framework that I have been working on didn’t integrate well. I have to go back and look to see if I can make this integration a little easier, because I want both.

Enjoy the coding, and check out ComponentOne Studio for Entity Framework.

Disclosure of Material Connection: I received one or more of the products or services mentioned above for free in the hope that I would mention it on my blog. Regardless, I only recommend products or services I use personally and believe my readers will enjoy. I am disclosing this in accordance with the Federal Trade Commission’s 16 CFR, Part 255: “Guides Concerning the Use of Endorsements and Testimonials in Advertising”.

Updated – 7/30/2012 – Fixing a couple mistakes, like the product name *oops*

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionImages have gone amiss? Pin
Duncan Edwards Jones11-Apr-14 6:22
professionalDuncan Edwards Jones11-Apr-14 6:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.