My opinion about O/R Mappers has been
changing rapidly since I started
researching
LLBLGen Pro.
In fact, I just persuaded a client to buy it. Why? Well, there's lot's of
reasons, but here's one reason in a nice demo format...
Within five minutes, I can generate an scalable object
model using the
adapter scenario along with a set of
manager templates
(that
someone was nice enough to write and share with the rest of us). Then create a VS2005 Web project that uses the
ObjectDataSource control that is bound to by a GridView. The ObjectDataSource
points to the following method like so....
using
System.Collections.Generic;
using
NorthWind.EntityClasses;
using
NorthWind.Core.Managers;
using
NorthWind.HelperClasses;
public
class Customers
{
public List<CustomersEntity>
GetCustomers() {
EntityCollection entities =
CustomersManager.FetchCollection();
List<CustomersEntity>
customers = new
List<CustomersEntity>();
foreach (CustomersEntity
cust in entities)
customers.Add(cust);
return customers;
}
}
<asp:ObjectDataSource
ID="ObjectDataSource1"
runat="server"
SelectMethod="GetCustomers"
TypeName="Customers"></asp:ObjectDataSource>
<asp:GridView
AutoGenerateColumns="false"
DataSourceID="ObjectDataSource1"
ID="GridView1"
runat="server">
<Columns>
<asp:BoundField
DataField="CustomerID"></asp:BoundField>
<asp:BoundField
DataField="CompanyName"></asp:BoundField>
</Columns>
</asp:GridView>
As you can see, I'm binding against a generic list just to have some fun
with
generics, but I could just as easily write the GetCustomers() method to
simply return an EntityCollection object...
public
EntityCollection GetCustomers() {
return
CustomersManager.FetchCollection();
}
Or I can go really crazy and have no C# code at all like this...
<asp:ObjectDataSource
ID="ObjectDataSource1"
runat="server"
SelectMethod="FetchCollection"
TypeName="NorthWind.Core.Managers.CustomersManager"
/>
<asp:GridView
AutoGenerateColumns="False"
DataSourceID="ObjectDataSource1"
ID="GridView1"
runat="server">
<Columns>
<asp:BoundField
DataField="CustomerID"></asp:BoundField>
<asp:BoundField
DataField="CompanyName"></asp:BoundField>
</Columns>
</asp:GridView>
Pretty cool stuff, huh? :-)