2009-12-28 25 views
0

对于域实体的以下表映射样式,您如何看待?强类型映射。基于Lambda表达式的ORM

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;); } } 
} 

我试图实现的,是有我的域模型准备编写代码反对,只要我键入和编译,而无需任何代码生成程序和依赖任何XML工件,并有能力强烈引用我正在处理的所有事情。

不管它如何实施,你认为这样很容易使用它吗?

回答

2

FluentNHibernate确实几乎相同的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); 
    } 
} 

此外,它还支持所谓的自动映射:

var autoMappings = AutoPersistenceModel 
    .MapEntitiesFromAssemblyOf<Product>() 
    .Where(t => t.Namespace == "Storefront.Entities"); 

var sessionFactory = new Configuration() 
    .AddProperty(ConnectionString, ApplicationConnectionString) 
    .AddAutoMappings(autoMappings) 
    .BuildSessionFactory();