Project: DataAnnotations


Use the same DataAnnotations for:
  1. mapping for NHibernate 3.2
  2. mapping for EntityFramework
  3. metadata class to validate ASP.NET MVC ViewModel

So you can easily switch between NHibernate and EntityFramework!

The domain class:
[MetadataType(typeof(VehicleMetadata))]
public class Vehicle
	: Entity<Guid>, IVehicle
{
	public virtual string Name { get; set; }
}

The metadata class that defines DataAnnotations:
public class VehicleMetadata
	: EntityMetadata,
	IVehicle
{
	[Required]
	[StringLength(30)]
	public string Name { get; set; }
}

The Unit Of Work ORM-agnostic interface:
public interface IVehicleUnitOfWork
	: IDisposable
{
	IRepository<Vehicle> VehicleRepository { get; }

	void Commit();
}

At the and the configuration using NHIbernate "by-code" mapping:
var mapper = new DataAnnotationsModelMapper();
mapper.Map<Vehicle>();

Last edited Oct 26, 2011 at 10:58 AM by teoarch, version 1

Comments

No comments yet.