NHibernate-是否有生成POCO的工具?

NHibernate-是否有生成POCO的工具?,nhibernate,fluent-nhibernate,poco,Nhibernate,Fluent Nhibernate,Poco,我正在考虑使用NHibernate,一切看起来都很好。是否有一个工具可用于从当前数据库生成POCO?这将加快开发人员的时间,而不是创建它们。Entity Framework Power Tools可以从数据库为您生成POCO。有关详细信息,请参阅。不过,您可能需要稍微调整一下流程;稍微调整一下可以产生非常好的结果: 如果所有内容都对齐,则我们根本不生成任何映射: 当然,如果一切都不一致,那么您将应用需要删除的实体框架特定属性。但你仍然有一个很好的起点 个人意见提醒!另一种可能是简单地保留属性并使

我正在考虑使用NHibernate,一切看起来都很好。是否有一个工具可用于从当前数据库生成POCO?这将加快开发人员的时间,而不是创建它们。

Entity Framework Power Tools可以从数据库为您生成POCO。有关详细信息,请参阅。不过,您可能需要稍微调整一下流程;稍微调整一下可以产生非常好的结果:

如果所有内容都对齐,则我们根本不生成任何映射:

当然,如果一切都不一致,那么您将应用需要删除的实体框架特定属性。但你仍然有一个很好的起点


个人意见提醒!另一种可能是简单地保留属性并使用实体框架。如果您大量使用LINQ,我会推荐它。我发现NHibernate的LINQ提供程序在大部分情况下都能工作,但却只使用了1个极其简单的LINQ表达式和2个极其复杂的LINQ表达式。但是助教斯佩特是!情况一直在好转!每个都有自己的映射,但目前实体框架的LINQ提供程序非常一致。

NHibernate映射生成器项目可以创建实体类和所有形式的映射XML、fluent NHibernate等。

下面是一个创建poco和映射的快速SQL脚本。根据需要随时调整

    begin

    declare @tablename varchar(200)
    set @tablename = 'tablename'

    declare @outputTable table ( id int identity(1,1), rowType varchar(4), outputString varchar(5000))
    declare @columnname varchar(200)
    declare @isNullable bit
    declare @xtype tinyint
    declare @xtypeString varchar(200)
    declare @outputString varchar(5000)

    declare c1 cursor for 
        select name, isnullable, xtype from syscolumns
            where id in (select id  from sysobjects where name = @tablename)
            order by colorder

    open c1

    set @outputString = 'Table("' +  Upper(@tablename) + '");'

    insert into @outputTable (rowType, outputString) values('map',@outputString)

    fetch next from c1 into @columnName, @isNullable, @xtype
    while(@@FETCH_STATUS=0)
    begin

    print @columnname
    print @isnullable
    print @xtype

    set @outputString = ''
    set @xtypeString = ''

    if (@xtype = 104)
        set @xtypeString = 'bool'

    if (@xtype = 60)
        set @xtypeString = 'double'

    if (@xtype = 62)
        set @xtypeString = 'double'

    if (@xtype = 175)
        set @xtypeString = 'string'

    if (@xtype = 56)
        set @xtypeString = 'int'

    if (@xtype = 48)
        set @xtypeString = 'int'

    if (@xtype = 167)
        set @xtypeString = 'string'

    if (@xtype = 61)
        set @xtypeString = 'DateTime'

    if (@isnullable = 1 and len(@xtypeString) > 0 and @xtypeString <> 'string') 
        set @xtypeString = @xtypeString + '?'

    if @xtypeString=''
        set @xtypeString = cast(@xtype as varchar)

    set @outputString = 'public virtual ' + @xtypeString + '   ' +  @columnName + '  {get;set;}          //  ' + @columnname

    insert into @outputTable (rowType, outputString)    values('poco', @outputString)

    set @outputString = 'Map(x => x.'+ @columnname+').Column("' + @columnname+'");'

    insert into @outputTable (rowType, outputString)    values('map', @outputString)


    fetch next from c1 into @columnName, @isNullable, @xtype
    end

    close c1
    deallocate c1

    select * from @outputTable where rowType = 'poco' order by id 
    select * from @outputTable where rowType = 'map' order by id 
end