Friday, December 7, 2012
MySql Support
Multi Tenancy Support
Tuesday, June 5, 2012
MySql Project
Thursday, May 31, 2012
New Database Support
Take the Survey
Monday, February 21, 2011
Database Generator
Saturday, February 19, 2011
Deep Dive: ADO.NET Generator
Monday, February 14, 2011
Generator Library
Sunday, December 5, 2010
4.0 Version
Friday, December 3, 2010
Select Commands
Table Auditing
Concurrency
Tuesday, August 31, 2010
Does NHibernate save time?
Thursday, July 22, 2010
Features of the nHydrate DAL and Entity Framework generators: Part 1 Auditing
The core of this article will be to explain the auditing features available in nHydrate. Providing the ability to audit database changes is a useful feature for many systems. As such, nHydrate has provided a framework that makes implementing an auditing solution for your project pain free. The examples provided in the article will work on both the traditional nHydrate Data Access Layer (NHDAL) as well as the nHydrate Entity Framework Data Access Layer (EFDAL).
As a precursor to this document you may want to check out the following articles
NHydrate Step-by-Step
Entity Framework with nHydrate
Why implement an Entity Framework based DAL in nHydrate?
What’s in the Model?
Let us start by taking a look at the properties in the model that deal with auditing.
Audit Field Names
The first is on the database node of the nHydrate model. Here you can identify what names you want to apply to your audit fields. These fields will be added to entities that specify they wish to be audited. The following properties are provided: CreatedByColumnName, CreatedDateColumnName, ModifiedByColumnName, ModifiedDateColumnName.Table Level Audit Settings
For each table in the model, nHydrate provides the ability to turn on or off table level auditing. There are three settings to consider- AllowCreateAudit - This is a true false setting. When the value is true the table will have two columns placed on it: created_by and created_date. These fields are set the first time a user inserts the record.
- AllowModifyAudit - This is a true false setting. When the value is true the table will have two columns placed on it: modified_by and modified_date. These fields are reset each time a user updates the record
- AllowAuditTracking - This is a true false setting. When true it identifies that a new database table will be created to hold historical audit information.
What’s in the API?
Although the generated frameworks for nHydrate DAL and Entity Framework are slightly different. They both provide means for implementing the auditing features.In the below examples pay particular attention to the following:
- First we will identify how to set the identity of the user performing the changes. This will allow the framework to setup the modifiedby and createdby columns without requiring the developer to set it on every object.
- There is also a convenience method added to every object that allows you to pull back a history of the modifications. In this way it is very easy to manage rollbacks or present object histories from the API. The convenience method used in this example brings back all audit records. (NOT SHOWN) This method has been overloaded to deal with large audit sets.
- instance.GetAuditRecords() - All audit records for the instance
- instance.GetAuditRecords(int pageOffset, int recordsPerPage) - Paginated records for the instance
- instance.GetAuditRecords(int pageOffset, int recordsPerPage, DateTime? startDate, DateTime? endDate) - Paginated records for the instance between dates. recordsPerPage=0, pageOffset=0 : returns all records between the dates.
nHydrateDAL - Example
// Add a couple of customer objects. You will notice that during the creation of the customer collection
// we pass the modifier. We are also not setting modified_by, modified_on, created_by or created_on
// fields. These are implemented by the framework.
CustomerCollection customerCollection = new CustomerCollection("User14");
//Create a simple customer
//When persisted create record will be added to the audit table
Customer simpleCustomer = customerCollection.NewItem();
simpleCustomer.Name = "Simple Customer";
customerCollection.AddItem(simpleCustomer);
//Create another customer
//When persisted Create record will be added to the audit table
Customer customer = customerCollection.NewItem();
customer.Name = "Test Name 1";
customerCollection.AddItem(customer);
//Persist both customers they will both have the modifier or User14
customerCollection.Persist();
//Update the name. Updated record will be added to audit table
customer.Name = "Test Name 2";
customerCollection.Persist();
//Lets look at what the create a modify produced
//Retrieve customer from database that we just saved.
Customer auditedCustomer = Customer.SelectUsingPK(customer.CustomerId, "User15");
//Write Audit Records. There will be two records.
//The first record will represent the creation.
//The second record will represent the modification.
foreach (CustomerAudit customerAudit in auditedCustomer.GetAuditRecords())
{
Console.WriteLine("AuditDate: " + customerAudit.AuditDate.ToString());
Console.WriteLine("AuditType: " + customerAudit.AuditType.ToString());
Console.WriteLine("CustomerId: " + customerAudit.CustomerId.ToString());
Console.WriteLine("Name: " + customerAudit.Name);
Console.WriteLine("ModifiedBy: " + customerAudit.ModifiedBy);
}
EFDAL - Example
Guid createdCustomerID = Guid.Empty;
// Add a couple of customer objects. You will notice that during the creation of the ObjectContext
// (AuditExampleEntities). We provide a context startup object that specifies the modifying user
// We are also not setting modified_by, modified_on, created_by or created_on fields. These are
// implemented by the framework.
ContextStartup user14Startup = new ContextStartup("User14");
using (AuditExampleEntities context = new AuditExampleEntities(user14Startup))
{
//Create a simple customer
//When persisted create record will be added to the audit table
Customer simpleCustomer = new Customer();
simpleCustomer.Name = "Simple Customer";
context.AddItem(simpleCustomer);
//Create another customer
//When persisted Create record will be added to the audit table
Customer customer = new Customer();
customer.Name = "Test Name 1";
context.AddItem(customer);
//Persist both customers they will both have the modifier or User14
context.SaveChanges();
//Update the name. Updated record will be added to audit table
customer.Name = "Test Name 2";
context.SaveChanges();
createdCustomerID = customer.CustomerId;
}
//Lets look at what the create a modify produced
using (AuditExampleEntities context = new AuditExampleEntities(user14Startup))
{
//Retrieve customer from database that we just saved.
Customer customer = context.Customer.
Single(cust => cust.CustomerId == createdCustomerID);
//Write Audit Records. There will be two records.
//The first record will represent the creation.
//The second record will represent the modification.
foreach (CustomerAudit customerAudit in customer.GetAuditRecords())
{
Console.WriteLine("AuditDate: " + customerAudit.AuditDate.ToString());
Console.WriteLine("AuditType: " + customerAudit.AuditType.ToString());
Console.WriteLine("CustomerId: " + customerAudit.CustomerId.ToString());
Console.WriteLine("Name: " + customerAudit.Name);
Console.WriteLine("ModifiedBy: " + customerAudit.ModifiedBy);
}
}
What’s in the database?
Within the database, additional columns are added to the tables when AllowCreateAudit or AllowModifyAudit are set to true. Taking the customer table as an example, we see the existence of CreatedBy, CreatedOn, ModifiedBy and ModifiedOn.
The next thing that you will notice is a new table has been created in the database schema. This table is where the audit records are kept. This is a result of specifying AllowAuditTracking to true on the customer table settings
Database Diagram for Audit Model
Now we can look at the results from running our code. Within the database we will notice that auditing fields have data for both of the customers we added. This occurred without the overhead of a developer expressly setting them on every object that is stored. We will also see that the audit records have been established in the __AUDIT__Customer database table.
Customer and __Audit__Customer Results.
Miscellaneous
- The framework can set ModifiedDate, CreatedDate and __insertdate as UTC or Local values. Depending on the UseUTCTime setting, all of these times are established on the database server.
- Manually setting the ModifiedDate or CreatedDate will override the values set by the framework.
- The database stores an integer to identify the audit actions. 1 = Create, 2 = Update, 3 = Delete
- Fields that are of type text, ntext, or image are not available in the audit tables.
Sunday, July 11, 2010
Why implement an Entity Framework based DAL in nHydrate?
Although nHydrate is only a year old from an open source perspective, it was originally created over five years ago on the .Net 1.1 framework. During this time, nHydrate sets out to enhance the data access experience using a Model Driven Architecture (MDA) approach. Using this approach required us to provide a model at a higher level of abstraction than a typical data access layer. Our core focus was to ease the pains of evolutionary database design while maintaining a robust data access layer (DAL).
The nHydrate team has always been dedicated to staying up with the latest Microsoft technologies. As a team, we do not wish to be stuck on an out of date technology. Over the past couple of years, we have watched carefully as Entity Framework (EF) has evolved. It was not until the release of 4.0 that we felt it would be viable for us to provide an EF solution. The advent of a viable Entity Framework architecture, also allowed us to demonstrate the flexibility of a MDA based application. Using the same model, developers can generate very different DAL solutions.
At this point I feel it is important to identify our continued dedication to the current Data Access Layer (DAL). There are many applications in production today that depend on this architecture. Entity Framework 4.0 is not a good solution for many of them. Specifically, applications that wish to provide a DAL that consists of hundreds of tables. For these reasons the current solution is core to what we do and must continue to be a focus.
To get a good answer to this question you must look at our past. The majority of our current architecture is built on Dataset technology. When we originally investigated this technology two things became evident. First, the models that drove the dataset were created at the project level. We felt that an MDA based application should have a model at the solution level. Second, there were several improvements that could be built on top of this architecture. Anyone who looks at the nHydrate architecture today would verify that it has many advantages over strait datasets. Entity Framework is not an exception to either of these realizations.
Taking a more concrete look at the current EFDAL release the following items are addressed:
- Evolutionary database management – The current database product has been adjusted to capture the needs of the Entity Framework model. The nHydrate team is bringing evolutionary database concepts to an Entity Framework solution. For those using nHydrate today, another important realization should be made. The EFDAL and the nHydrate DAL can on the same database. Making a mixed implementation possible today and a migration path available in the future.
- Type Tables – Managing enumerations in your code and database can be a cumbersome task. nHydrate solves this by allowing users to define type tables that present themselves as enumerations in the DAL. Example: In the Order table we need to persist an Order Status column that represents one of the following values Created, Packaged, Shipped, or Received. The management of this enumeration in the code can be handled by adding a type table to the nHydrate model.
- Stored Procedure Generation – All insert, update and delete functions are automatically mapped to stored procedures.
- Property Level Eventing – The entity objects are provided with an event model that allows users to hook into specific property changes.
- Explicit partial class generation – If you have used our generator in the past you would notice that we like to generate an editable partial class file as a parent to the code generation file. In the below example the Customer.cs file contains a partial class that is used to extend the generated Customer object in Customer.Generated.cs file.

- Convenience property for derived table – An example of querying the derived shape circle is below.

- Implicit Load - Automated calls to load method the first time a property is walked.
To learn more please download the sample project at http://bit.ly/c9PmCz. Also, follow us on twitter or join our linked in group. More documentation and examples will be provided through our blog, the code project, CodePlex and You Tube. The best ways to monitor these events is to follow our twitter feed or subscribe to the LinkedIn group. The side of this blog provides a link to these social networking sites.
The majority of this question will be answered by the users that provide us with feedback. However, there are a few things that we must support. First, we must provide a solution that provides a transition path between the competing data access layers. Second, we have a short list of features that we wish to support on Entity Framework over the next few weeks:
- Auditing – Modifier established at context level, Creation of audit tables automatically filled through create, update and delete operations.
- Bulk operations - update, insert and delete
- Generation of a RIA services project.
Sunday, May 9, 2010
Performance Tests
- Aggregate count of users with a last name
- Select a list of users by last name
- Select each user by primary key
- Walk to related jobs for each user
- Walk to a parent user for each job
Sunday, May 2, 2010
VS.NET 2010
Thursday, April 1, 2010
Demo Complete
In the demo we went over ORM and MDA. We created a simple object add and dependency walking. We also showed the aggregates and bulk data operations. The Lambda syntax was quite impressive as was the inheritance table splitting. At the end, we touched on the IoC framework with POCO objects and such.
Many people were interested in the jQuery scaffolding with grids and data interaction. We discussed generating some of the UI in the future with customizable grid and other features. We also had a discussion about where future development should focus. Currently we are focused on jQuery however we may need to focus on Silverlight. This really requires more discussing from users about the best direction to go.
The model will be changing in the near future to add some new functionality like grids, enhanced UI generation and scaffolding and perhaps some other new stuff as well. Feel free to comment on this blog. We are also going to start sending out surveys to get feedback of desired technologies and functionality soon.
All in all we were very happy with the response and look forward to doing it again.
Monday, March 15, 2010
Orlando Code Camp
http://www.orlandocodecamp.com/Agenda.aspx/Sessions