What do you think of the following table mapping style for domain entities?
class Customer {
public string Name;
}
class Order
{
public TotallyContainedIn<Customer> Parent { get { return null; } }
public HasReferenceTo<Person> SalesPerson { get { return new HasReferenceTo<Person>(0,1); } }
}
//...
[TableOf(typeof(Customer))]
class CustomerTable
{
//...
public Mapping Name { get { return Column.Implements<Customer>(c=>c.Name); } }
}
[TableOf(typeof(Order))]
class OrderTable
{
//...
public FK 开发者_如何学运维CustomerID { get { return References.FK<CustomerTable>(ct=>ct.Id;); } }
}
What I'm trying to achieve, is having my domain model ready for writing code against as soon as i type that and compile, without a need for any code generation routines and dependence on any xml artifacts, and with ability to strongly reference everything i'm working with.
No matter how it will be implemented, do you think it would be easy to use it this way?
FluentNHibernate does practically the same for NHibernate:
public class CatMap : ClassMap<Cat>
{
public CatMap()
{
Id(x => x.Id);
Map(x => x.Name)
.Length(16)
.Not.Nullable();
Map(x => x.Sex);
References(x => x.Mate);
HasMany(x => x.Kittens);
}
}
Additionally, it supports so-called automapping:
var autoMappings = AutoPersistenceModel
.MapEntitiesFromAssemblyOf<Product>()
.Where(t => t.Namespace == "Storefront.Entities");
var sessionFactory = new Configuration()
.AddProperty(ConnectionString, ApplicationConnectionString)
.AddAutoMappings(autoMappings)
.BuildSessionFactory();
精彩评论