.NET活动记录ORM具有完全的迁移支持 [英] .net Active Record ORM with full migration support

查看:109
本文介绍了.NET活动记录ORM具有完全的迁移支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一个使用活动记录模式,并允许开发人员定义的迁移,将更新code数据库方案的.NET或/ M。我看到过的ActiveRecord在 http://www.castleproject.org/activerecord/index.html - 但它是不良记录(与可怕的过时的样品),并没有投入生产版本中提供。我的目标DBMS是2008 MSSQLE;但是preferably生成的SQL将是MSSQL 2000兼容。

我宁愿不使用NHibernate的,按照我的理解,需要一个XML文件来维护方案,具有迁移的支持。随着.NET反射和属性,在这种情况下,一个图书馆的使用XML是不可接受的,不会觉得很原产于平台的一般使用。

我最关心的是保持databsae方案。由于这是一个ASP.NET MVC项目,能够保持数据库模式的同步环境之间是必须的。我无法找到一个或/ M内置的迁移支持,这是惊人的考虑.NET的普及 - 因为,就像我之前说的,自定义属性和反射使这个很容易做到在code。

由于能够无需外部配置文件(ALA ADO.NET实体框架)我的实体类以外的定义我的实体也是我想避免的东西。没有理由为什么OR / M无法通过使用自定义的推断列名属性的相关属性。

总之,有什么建​​议?我所要求的是也许是不存在的;如果是的话,是否有使用其它.NET或/小姐的任何第一手资料,你可以分享?

解决方案
  

我宁愿不使用NHibernate的,因为   我知道它需要一个XML文件   维护计划

你有没有看着流利,NHibernate的,它允许您使用流利的.NET API定义的模型。

从网站实例:

 公共类CatMap:ClassMap<猫>
{
  公共CatMap()
  {
    ID(X => x.Id);
    地图(X => x.Name)
      .Length(16)
      .Not.Nullable();
    地图(X => x.Sex);
    参考文献(X => x.Mate);
    的hasMany(X => x.Kittens);
  }
}
 

(流利,NHibernate的还支持自动映射的基础上,约定)

的NHibernate还支持<一个href="http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/28/create-and-update-database-schema.aspx"相对=nofollow>模式创建和更新。模式创建工作的一种享受,我以前在网上项目和存储器单元测试中使用了很多次。因为我一直在使用未使用更新功能尚未 Migrator.NET 为处理这一段时间。

I'm looking for a .net OR/M that uses the Active Record pattern and allows the developer to define migrations that will update the database scheme in code. I have seen ActiveRecord over at http://www.castleproject.org/activerecord/index.html - but it is poorly documented (with terribly out of date samples) and there is no production ready release available. My target DBMS is MSSQLE 2008; but preferably the generated SQL will be MSSQL 2000 compatible.

I would rather not use nHibernate, as I understand it requires an XML file to maintain the scheme and has no support for migrations. With .net reflection and attributes, a library's use of XML in this situation is unacceptable and doesn't feel very native to the platform's general use.

My main concern is with maintaining the databsae scheme. As this is for a ASP.NET MVC project, being able to keep database scheme's in sync between environments is a must. The fact that I can't find a single OR/M with built in migration support is amazing considering the popularity of .net - as, like I said before, custom attributes and reflection make this very easy to accomplish in code.

Being able to define my entities without an external configuration file (ala ADO.NET Entity Framework) outside of my entity class is also something that I want to avoid. There is no reason why the OR/M can't infer column names by the use of custom attributes on the associated properties.

Anyway, are there any suggestions? What I am asking for is perhaps non-existent; and if so, are there any first hand accounts of using other .net OR/Ms that you can share?

解决方案

I would rather not use nHibernate, as I understand it requires an XML file to maintain the scheme

Have you looked into Fluent-NHibernate, it allows you to define your models using a fluent .net API.

Example from site:

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

(Fluent-NHibernate also supports auto-mappings, based on convention)

NHibernate also support Schema Creation and Updating. Schema Creation works a treat, I've used this many times before in web-projects and in-memory unit tests. Haven't used the Updating feature yet because I've been using Migrator.NET for a while that handles this.

这篇关于.NET活动记录ORM具有完全的迁移支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆