[英]Strongly typed mapping. Lambda Expression based 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工件的依賴,並且能夠強烈引用我正在合作。
無論如何實施,您是否認為以這種方式使用它會很容易?
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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.