Project: DataAnnotations
Use
the same DataAnnotations for:
- mapping for NHibernate 3.2
- mapping for EntityFramework
- 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>();