We are happy to announce that
Q3 2012 SP1 of
OpenAccess ORM is now released. In addition to the number of bug fixes, we have included a bunch of useful enhancements.
Check the entire release notes to see the full list of improvements shipped with the latest update. Here are the highlights:
- Multi-Table Entities Mapping - the ability to map multiple tables to one single Domain Class
- Additional API for working with String arrays Code-Only
- GUID generator ranges bring easier data synchronization
Probably the most exciting new enhancement in OpenAccess Q3'12 SP1 is the Multi-Table Entities support. In order to get you acquainted with this new feature's usage, we would like to present to you a simple scenario that illustrates how it could come in very handy. Let’s assume you have the following tables in your database:
The design of the database above probably meant to fit a use case where you would need the
CustomerMain data much more frequently so it contains the most important set of columns, whilst the
CustomerDetail table contains those that are not mandatory and would be rarely used. Also it might be the case that the columns in each table are dozens, hundreds or even thousands.
As we would like to benefit from the complete flexibility of implementation offered by OpenAccess ORM, we would choose to go with Code-Only mapping using the Fluent Mapping API instead of the more simple Visual Designer. By default we define one Domain Class for each table, so we expose the following entry points for accessing the collections of objects:
public
IQueryable<CustomerMain> CustomerMains
{
get
{
return
this
.GetAll<CustomerMain>();
}
}
public
IQueryable<CustomerDetail> CustomerDetails
{
get
{
return
this
.GetAll<CustomerDetail>();
}
}
However, from the perspective of your business logic, it doesn't make much sense to have two different collections. In fact, we would like to have a single point of accessing the customer data, regardless of the database schema separation. Something like this:
public
IQueryable<Customer> Customer
{
get
{
return
this
.GetAll<Customer>();
}
}
In this case we would prefer to have easy access to all the columns through this Customer class. For instance:
Customer customer =
new
Customer()
{
Name =
"John Smith"
,
// from CustomerMain
Type =
"Individual"
,
// from CustomerMain
Country =
"US"
// from CustomerDetail
};
This is where the new overload we have created for the
ToColumn() method in Fluent API can prove its value. Previously the only argument in it was the name of the column mapped to the property, but now you can also optionally specify the table name. Thus, the mapping for the Customer type looks like:
MappingConfiguration<Customer> configuration =
new
MappingConfiguration<Customer>();
configuration.MapType(x =>
new
{ }).ToTable(
"CustomerMain"
);
configuration.HasProperty(x => x.Id).IsIdentity().HasFieldName(
"_id"
)
.ToColumn(
"Id"
).IsNotNullable().HasColumnType(
"int"
).HasPrecision(0).HasScale(0);
//... the rest of CustomerMain properties
configuration.HasProperty(x => x.Country).HasFieldName(
"_country"
)
.ToColumn(
"Country"
,
"CustomerDetail"
).IsNullable().HasColumnType(
"nvarchar"
).HasLength(30);
//.. the rest of CustomerDetail properties
In other words, all we have to do in order to map a class to a table different than the master table defined with
ToTable is to mention the name of the other table in the
ToColumn statement.
After this mapping is defined, you can just work with the Customer object and OpenAccess ORM will take care for the rest implicitly!
We hope that the flexibility that this new feature provides "out of the box" will be useful in your applications. Download
OpenAccess ORM Q3'12 SP1 and try it for yourself. Stay tuned as we will soon present the latest enhancements in the OpenAccess SDK!