Template Code
<%#NAMESPACE System.IO, System.Text, System.Text.RegularExpressions, System.Globalization%><% public class GeneratedTemplate : DotNetScriptTemplate { // 前缀 protected string _prefix; protected string _NullSufix; protected bool _CreatingXML; //选中的表 private IList _selectedTables; //选中的视图 private IList _selectedViews; //数据库名 private string _dbName; //表名 private string _tableName; //类名 private string _className; //输出路径 private string _exportPath; //文件名 private string _fileName; //命名空间 private string _nameSpace; //创建类文件 private bool _createClassFiles; //创建XML文件 private bool _createXmlFiles; //只读访问 private bool _createReadOnly; //创建Equals和HashCode private bool _generateEqualsHashCode; //在构造函数中使用Null private bool _useNull; //不创建外健引用 //private bool _dontCreateFK; //使用Lazy类 private bool _enableLazyClass; //启用nullable类型 private bool _enableNullTypes; //程序集名称 private string _assembly; public GeneratedTemplate( ZeusContext context ) : base( context ) {} public override void Render() { _dbName = input["chooseDatabase"].ToString(); _selectedTables = input["chooseTables"] as ArrayList; _selectedViews = input["chooseViews"] as ArrayList; _exportPath = input["outputPath"].ToString(); _nameSpace = input["classNamespace"].ToString(); _prefix = input["memberPrefix"].ToString(); _createClassFiles = (bool)input["chkClass"]; _createXmlFiles = (bool)input["chkMapping"]; _createReadOnly = (bool)input["chkReadOnly"]; _generateEqualsHashCode = (bool)input["chkEqualsHashCode"]; _useNull = (bool)input["chkUseNull"]; //_dontCreateFK = (bool)input["chkDontCreateFK"]; _enableLazyClass = (bool)input["chkLazyClass"]; _enableNullTypes = (bool)input["chkEnableNullTypes"]; _assembly=input["txtAssembly"].ToString(); _NullSufix = (_enableNullTypes ? "?" : ""); foreach( string _newTable in _selectedTables ) { ITable _workingTable = MyMeta.Databases[_dbName].Tables[_newTable]; _tableName = _workingTable.Alias; _className = TableNameToClassName(_tableName) ; if( _createClassFiles ) { GenerateClassFile( _workingTable.Columns ); } if( _createXmlFiles ) { GenerateMappingFile( _workingTable.Columns ); } } foreach( string _newView in _selectedViews ) { IView _workingView = MyMeta.Databases[_dbName].Views[_newView]; _tableName = _workingView.Alias.Replace( " ", "" ); _className = TableNameToClassName(_tableName); if( _createClassFiles ) { GenerateClassFile( _workingView.Columns ); } if( _createXmlFiles ) { GenerateMappingFile( _workingView.Columns ); } } } private void GenerateClassFile( IColumns Columns ) { _CreatingXML =false; %>/* /*NHibernate映射代码模板 /*作者:DDL /*版本更新和支持:http://renrenqq.cnblogs.com/ /*日期:2006年8月24日 */ using System; namespace <%= _nameSpace %> { /// <summary> /// /// </summary> [Serializable] public <%=(_enableLazyClass ? "" : "sealed ")%>class <%= _className %> { <% BuildPrivateMembers( Columns ); %> <% BuildDefaultConstructor( Columns ); %> <% BuildPublicAccessors( Columns ); %> <% BuildPublicFunctions( Columns ); %> <% if( _generateEqualsHashCode ) BuildEqualsHashCodeOverrides( Columns ); %> } } <% _fileName = _className + ".cs"; output.saveEnc( Path.Combine( _exportPath, _fileName ), false ,Encoding.GetEncoding("utf-8") ); output.clear(); } private void GenerateMappingFile( IColumns Columns ) { _CreatingXML =true; BuildHBMDefinition( Columns ); _fileName = _className + ".hbm.xml"; output.saveEnc( Path.Combine( _exportPath, _fileName ), false ,Encoding.GetEncoding("utf-8") ); output.clear(); } private void BuildDefaultConstructor( IColumns Columns ) { %>#region 默认( 空 ) 构造函数 /// <summary> /// 默认构造函数 /// </summary> public <%= _className %>() {<% foreach( IColumn field in Columns ) { string fieldName = ToVariableName(field.Alias); string fieldType = ColumnToNHibernateType(field ); if( fieldType.EndsWith( "[]" ) ) {%> <%= fieldName %> = new <%= fieldType %>{}; <% } else { switch( fieldType ) { case "string":%> <%= fieldName %> = <% if(_useNull){ %>null; <% } else {%> String.Empty; <% } break; case "DateTime":%> <%= fieldName %> = DateTime.MinValue; <% break; case "bool":%> <%= fieldName %> = false; <% break; case "decimal": case "float": case "byte": case "short": case "int": case "long":%> <%= fieldName %> = 0; <% break; default:%> <%= fieldName %> = <% if(_useNull){ %> null; <% } else {%> new <%= fieldType %>(); <% } break; case "Guid":%> <%= fieldName %>= Guid.Empty;<% break; } } }%> } #endregion<% } private void BuildEqualsHashCodeOverrides( IColumns Columns ) { %>#region 重写Equals和HashCode /// <summary> /// 用唯一值实现Equals /// </summary> public override bool Equals( object obj ) { if( this == obj ) return true; if( ( obj == null ) || ( obj.GetType() != GetType() ) ) return false; <%= _className %> castObj = (<%= _className %>)obj; <% if( CountUniqueFields( Columns ) == 0 ) {%> return castObj.GetHashCode() == this.GetHashCode()<% } else {%> return ( castObj != null )<% foreach( IColumn c in Columns ) { if( c.IsInPrimaryKey ) { %> && (<%= ToVariableName(c.Alias) %> == castObj.<%= c.Alias %> )<% } } } %>; } /// <summary> /// 用唯一值实现GetHashCode /// </summary> public override int GetHashCode() { <% if( CountUniqueFields( Columns ) == 0 ) { %>return this.GetType().FullName.GetHashCode(); <% } else {%>int hash = 57; <% foreach( IColumn c in Columns ) { if( c.IsInPrimaryKey ) { %> hash = 27 * hash * <%= ToVariableName(c.Alias) %>.GetHashCode();<% } } %> return hash; <% }%> } #endregion <% } private void BuildPrivateMembers( IColumns Columns ) { if( Columns.Count > 0 ) { %>#region 私有成员 private bool <%= _prefix %>IsChanged; private bool <%= _prefix %>IsDeleted;<% foreach( IColumn field in Columns ) { %> private <%= ColumnToNHibernateType(field) %> <%= ToVariableName(field.Alias) %>; <% } %> #endregion<% } } private void BuildPublicAccessors( IColumns Columns ) { if( Columns.Count > 0 ) { %>#region 公有属性 <% foreach( IColumn field in Columns ) { string fieldAccessor = field.Alias; string fieldName = ToVariableName(field.Alias); string fieldType = ColumnToNHibernateType( field ); %> /// <summary> /// <%= field.Description %> /// </summary> public <%=(_enableLazyClass ? "virtual" : "")%> <%= fieldType %> <%= fieldAccessor %> { get { return <%= fieldName %>; }<% if( !_createReadOnly ) { //if(!((field.IsInPrimaryKey && field.IsAutoKey) || field.IsComputed)) //{ switch( fieldType ) { default:%> set { <%= _prefix %>IsChanged |= (<%= fieldName %> != value); <%= fieldName %> = value; }<% break; case "byte": %> set { //if( value.Length > <%= field.CharacterMaxLength.ToString() %>) //throw new ArgumentOutOfRangeException("Invalid value for <%= fieldAccessor %>", value, value.ToString()); <%= _prefix %>IsChanged |= (<%= fieldName %> != value); <%= fieldName %> = value; } <% break; case "string": %> set { if ( value != null) if( value.Length > <%= field.CharacterMaxLength.ToString() %>) throw new ArgumentOutOfRangeException("Invalid value for <%= fieldAccessor %>", value, value.ToString()); <%= _prefix %>IsChanged |= (<%= fieldName %> != value); <%= fieldName %> = value; }<% break; } //} }%> } <% } %> /// <summary> /// 对象的值是否被改变 /// </summary> public bool IsChanged { get { return <%= _prefix %>IsChanged; } } /// <summary> /// 对象是否已经被删除 /// </summary> public bool IsDeleted { get { return <%= _prefix %>IsDeleted; } } #endregion <% } } private void BuildPublicFunctions( IColumns Columns ) {%>#region 公有函数 /// <summary> /// 标记对象已删除 /// </summary> public void MarkAsDeleted() { <%= _prefix %>IsDeleted = true; <%= _prefix %>IsChanged = true; } #endregion<% } private void BuildHBMDefinition( IColumns Columns ) { if( Columns.Count > 0 ) { output.writeln( "<?xml version=/"1.0/" encoding=/"utf-8/" ?>" ); output.writeln( NHibernateMappingTag() ); output.writeln( "/t" + NHibernateClassTag( Columns ) ); output.writeln( "/t/t" + NHibernatePrimaryKeysTag( Columns ) ); output.writeln( "/t/t" + NHibernateProperties( Columns ) ); output.writeln( "/t</class>" ); output.writeln( "</hibernate-mapping>" ); } } private string NHibernateMappingTag() { can't handle external mappings ?!? string xml = "<hibernate-mapping xmlns=/"http://nhibernate.sourceforge.net/schemas/nhibernate-mapping-2.0.xsd/""; //string xml = "<hibernate-mapping xmlns=/"urn:nhibernate-mapping-2.0/""; handle schemas, cascade, import, and access methods? //return xml + ">"; return "<hibernate-mapping xmlns=/"urn:nhibernate-mapping-2.2/">"; } private string NHibernateClassTag( IColumns Columns ) { //ITable t = Columns[0].Table; //IView v = Columns[0].View; //string desc = ( t == null ) ? v.Description : t.Description; StringBuilder xml = new StringBuilder(); xml.Append( "<class name=/"" ).Append( _nameSpace ).Append( "." ).Append( _className ).Append( "," ).Append( _assembly ).Append( "/"" ); xml.Append( " table=/"" ).Append( _tableName ).Append( "/"" ); if(_enableLazyClass) { xml.Append( " lazy=/"true/"" ); } if( _createReadOnly ) { xml.Append( " mutable=/"false/"" ); } // handle schema override, dynamic insert & update, and proxies? xml.Append( ">/r/n" ); return xml.ToString(); } private string NHibernatePrimaryKeysTag( IColumns Columns ) { StringBuilder xml = new StringBuilder(); int i = 0; foreach( IColumn c in Columns ) { if( c.IsInPrimaryKey ) { i++; } } if( i == 0 ) { return " <!-- could not find a primary key for this table/view. NHibernate requires an 'id' element, so you'll have to define one manually. -->"; } if( i == 1 ) { foreach( IColumn c in Columns ) { if( c.IsInPrimaryKey ) { xml.Append( "<id name=/"" ).Append( c.Alias ).Append( "/" column=/"" ); xml.Append( c.Alias ).Append( "/" type=/"" ).Append( ConvertNHibernate( ColumnToNHibernateType( c ) ) ).Append( "/"" ); switch( ColumnToNHibernateType( c ) ) { case "decimal": case "float": case "short": case "int": case "long": xml.Append( " unsaved-value=/"0/">/r/n" ); break; case "Guid": xml.Append( " unsaved-value=/"00000000-0000-0000-0000-000000000000/">/r/n" ); break; default: xml.Append( ">/r/n" ); break; } xml.Append( "/t/t/t<generator class=/"" ); xml.Append( GetGeneratorString(c)); xml.Append( "/"/>/r/n/t/t</id>" ); } } } if( i > 1 ) { xml.Append( "<composite-id access=/"field/">" ); xml.Append( "/r/n/t/t/t" ); foreach( IColumn c in Columns ) { if( c.IsInPrimaryKey ) { xml.Append(" <key-property name=/"").Append( c.Alias ).Append( "/" column=/"" ); xml.Append( c.Alias ).Append( "/" type=/"" ).Append( ConvertNHibernate( ColumnToNHibernateType( c ) ) ).Append( "/"" ); switch( ColumnToNHibernateType( c ) ) { case "decimal": case "float": case "short": case "int": case "long": xml.Append( " />/r/n" ); break; default: xml.Append( "/>/r/n" ); break; } xml.Append( "/t/t/t" ); } } xml.Append( "/r/n/t/t</composite-id>/r/n/t/t" ); } return xml.ToString(); } private string NHibernateProperties( IColumns Columns ) { StringBuilder xml = new StringBuilder(); foreach( IColumn c in Columns ) { if( !c.IsInPrimaryKey ) { // create sets & such for foreign keys !!! xml.Append( "<property column=/"" ).Append( c.Name ); xml.Append( "/" type=/"" ).Append( ConvertNHibernate( ColumnToNHibernateType( c ) ) ).Append( "/"" ); if( _createReadOnly ) { xml.Append( " access=/"field/" name=/"" ).Append( ToVariableName(c.Alias) ).Append( "/"" ); } else { xml.Append( " name=/"" ).Append( c.Alias ).Append( "/"" ); } if( !c.IsNullable ) { xml.Append( " not-null=/"true/"" ); } if( c.LanguageType == "string" ) { xml.Append( " length=/"" ).Append( c.CharacterMaxLength ).Append( "/"" ); } xml.Append( " />/r/n/t/t" ); } } return xml.ToString(); } // Methods public GeneratedTemplate(IZeusContext context) : base(context) { this._CreatingXML = false; this.ui = context.Objects["ui"] as GuiController; this.MyMeta = context.Objects["MyMeta"] as dbRoot; this.DnpUtils = context.Objects["DnpUtils"] as Dnp.Utils.Utils; } protected string ColumnToNHibernateType(IColumn Column) { string retVal = Column.LanguageType; switch (retVal) { case "sbyte": return "byte"; case "uint": return "int"; case "ulong": return "long"; case "ushort": return "short"; case "bool": case "decimal": case "float": case "byte": case "short": case "int": case "long": if (!this._CreatingXML && Column.IsNullable) { retVal = retVal + this._NullSufix; } return retVal; } return retVal; } protected string ConvertNHibernate(string Type) { string retVal = Type; switch (Type) { case "bool": return "Boolean"; case "byte": return "Byte"; case "sbyte": return "SByte"; case "char": return "Char"; case "decimal": return "Decimal"; case "double": return "Double"; case "float": return "Single"; case "int": return "Int32"; case "uint": return "UInt32"; case "long": return "Int64"; case "ulong": return "UInt64"; case "short": return "Int16"; case "ushort": return "UInt16"; case "string": return "String"; } return retVal; } protected int CountUniqueFields(IColumns Columns) { int i = 0; foreach (IColumn c in Columns) { if (!(c.IsNullable || !c.IsInPrimaryKey)) { i++; } } return i; } protected string GetGeneratorString(IColumn Column) { if (Column.DataTypeName == "uniqueidentifier") { return "guid"; } if (Column.IsAutoKey) { return "native"; } return "assigned"; } protected string TableNameToClassName(string tableName) { int index = tableName.LastIndexOf("_"); return tableName.Substring(index + 1); } protected string ToArgumentName(string name) { return this.ToLeadingLower(name); } private string ToLeadingLower(string name) { char[] chars = name.ToCharArray(); chars[0] = char.ToLower(chars[0]); return new string(chars); } protected string ToVariableName(string name) { return (this._prefix + name); } } %>
Interface Code
<%#REFERENCE System.Windows.Forms.dll %> <%#NAMESPACE System, System.Text, System.Collections, Zeus, Zeus.UserInterface, Zeus.DotNetScript, Microsoft.Win32 %> public class GeneratedGui : DotNetScriptGui { public GeneratedGui( ZeusGuiContext context ) : base( context ) {} GuiTextBox classNamespace; GuiTextBox txtAssembly; GuiTextBox outputPath; GuiTextBox memberPrefix; GuiCheckBox chkUseNull; //GuiCheckBox chkDontCreateFK; GuiCheckBox chkEqualsHashCode; GuiCheckBox chkReadOnly; GuiCheckBox chkClass; GuiCheckBox chkMapping; GuiCheckBox chkLazyClass; GuiCheckBox chkEnableNullTypes; public override void Setup() { RegistryKey reg ; reg = Registry.CurrentUser; reg = reg.CreateSubKey("Software"); reg = reg.CreateSubKey("DDLLY"); reg = reg.CreateSubKey("NHibernateScript"); if ( !input.Contains( "chooseTables" ) || !input.Contains( "txtPath" ) || ( !input.Contains( "chkClass" ) && !input.Contains( "chkNaming" ) ) ) { ui.Title = "DDL NHibernate Object Mapping"; ui.Width = 600; ui.Height = 550; // Grab default output path string sOutputPath = ""; if( input.Contains( "defaultOutputPath" ) ) { sOutputPath = input["defaultOutputPath"].ToString(); } //Posiciona a pasta no registro reg = Registry.CurrentUser; reg = reg.OpenSubKey("Software//DDLLY//NHibernateScript"); // Setup Folder selection input control. GuiLabel label1 = ui.AddLabel( "label1", "输出路径:", "输出路径" ); label1.Width = 200; outputPath = ui.AddTextBox( "outputPath", sOutputPath, "输出路径" ); outputPath.Width = 450; outputPath.Text = (string)reg.GetValue("outputPath", sOutputPath); GuiFilePicker selectPath = ui.AddFilePicker( "selectPath", "选择路径", "选择路径", "outputPath", true ); selectPath.Top = outputPath.Top; selectPath.Width = 100; selectPath.Left = outputPath.Left + outputPath.Width + 20; GuiLabel label2 = ui.AddLabel( "label2", "命名空间: ", "命名空间" ); label2.Top = outputPath.Top + 30; label2.Width = 265; classNamespace = ui.AddTextBox( "classNamespace", "NHibernate", "命名空间" ); classNamespace.Top = label2.Top + 20; classNamespace.Width = label2.Width; classNamespace.Text = (string)reg.GetValue("classNamespace", "NHibernate"); GuiLabel label3 = ui.AddLabel( "label3", "私有成员前缀: ", "私有成员前缀" ); label3.Width = 80; label3.Top = classNamespace.Top + 30; label3.Left = label2.Left; //Width + 20; memberPrefix = ui.AddTextBox( "memberPrefix", "m_", "" ); memberPrefix.Width = 80; memberPrefix.Top = label3.Top + 20; memberPrefix.Left = label2.Left; memberPrefix.Text = (string)reg.GetValue("memberPrefix", "m_"); GuiLabel label20 = ui.AddLabel ("label20", "程序集:", "程序集"); label20.Width = 160; label20.Top = classNamespace.Top + 30; label20.Left = label2.Left + 85; txtAssembly = ui.AddTextBox("txtAssembly", "Business.Data", "程序集"); txtAssembly.Width = 180; txtAssembly.Top = label3.Top + 20; txtAssembly.Left = classNamespace.Left + 85; txtAssembly.Text = (string)reg.GetValue("Assembly", "NHibernate"); // Setup Database selection combobox. GuiLabel label4 = ui.AddLabel( "label4", "选择一个数据库:", "选择一个数据库" ); label4.Width = label2.Width; GuiComboBox chooseDatabase = ui.AddComboBox( "chooseDatabase", "选择一个数据库" ); chooseDatabase.Top = label4.Top + 20; chooseDatabase.Width = label2.Width; GuiLabel label5 = ui.AddLabel( "label5", "选项:", "选项" ); label5.Width = 150; label5.Top = label2.Top; label5.Left = label2.Width + 20; chkClass = ui.AddCheckBox( "chkClass", "创建类文件", getBool(reg.GetValue("Class", "true")), "创建类文件(*.cs)" ); chkClass.Width = 150; chkClass.Top = label5.Top + 20; chkClass.Left = label5.Left; chkMapping = ui.AddCheckBox( "chkMapping", "创建XML映射文件", getBool(reg.GetValue("Mapping", "true")), "创建XML映射文件 (*.hbm.xml)" ); chkMapping.Width = 150; chkMapping.Top = chkClass.Top + 20; chkMapping.Left = chkClass.Left; chkReadOnly = ui.AddCheckBox( "chkReadOnly", "只读访问", getBool(reg.GetValue("ReadOnly", "false")), "创建只读访问对象和映射" ); chkReadOnly.Width = 130; chkReadOnly.Top = chkClass.Top; chkReadOnly.Left = chkClass.Left + chkClass.Width + 20; chkLazyClass = ui.AddCheckBox( "chkLazyClass", "启用Lazy类", getBool(reg.GetValue("LazyClass", "false")), "启用Lazy类" ); chkLazyClass.Width = 130; chkLazyClass.Top = chkReadOnly.Top + 20; chkLazyClass.Left = chkReadOnly.Left; chkUseNull = ui.AddCheckBox( "chkUseNull", "在构造函数中使用Null", getBool(reg.GetValue("UseNull", "true")), "在构造函数中使用Null" ); chkUseNull.Width = 200; chkUseNull.Top = chkMapping.Top + 20; chkUseNull.Left = chkMapping.Left; /* chkDontCreateFK = ui.AddCheckBox( "chkDontCreateFK", "不创建外键类引用", getBool(reg.GetValue("DontCreateFK", "true")), "不创建外键类引用" ); chkDontCreateFK.Width = 300; chkDontCreateFK.Top = chkUseNull.Top + 20; chkDontCreateFK.Left = chkMapping.Left; */ chkEqualsHashCode = ui.AddCheckBox( "chkEqualsHashCode", "创建Equals和GetHashCode", getBool(reg.GetValue("EqualsHashCode", "true")), "创建Equals和GetHashCode" ); chkEqualsHashCode.Top = chkMapping.Top + 20; chkEqualsHashCode.Left = chkMapping.Left; chkEqualsHashCode.Width = chkUseNull.Width; chkEnableNullTypes = ui.AddCheckBox( "chkEnableNullTypes", "启用nullable类型", getBool(reg.GetValue("EnableNullTypes", "true")), "在.Net2.0中启用nullable类型" ); chkEnableNullTypes.Top = chkEqualsHashCode.Top + 20; chkEnableNullTypes.Left = chkMapping.Left; chkEnableNullTypes.Width = chkUseNull.Width; // Setup Tables selection multi-select listbox. GuiLabel label7 = ui.AddLabel( "label7", "选择表:", "选择表" ); label7.Top = chooseDatabase.Top + 30; label7.Width = label2.Width; GuiListBox chooseTables = ui.AddListBox( "chooseTables", "选择表" ); chooseTables.Width = label7.Width; chooseTables.Height = 200; chooseTables.Top = label7.Top + 20; // Setup Views selection multi-select listbox. GuiLabel label8 = ui.AddLabel( "label8", "选择视图", "选择视图" ); label8.Top = label7.Top ; label8.Left = label7.Width + 20; label8.Width = chooseTables.Width; GuiListBox chooseViews = ui.AddListBox( "chooseViews", "选择视图" ); chooseViews.Top = label8.Top + 20; chooseViews.Left = label8.Left; chooseViews.Width = label8.Width; chooseViews.Height = chooseTables.Height; // Attach the onchange event to the cmbDatabases control. setupDatabaseDropdown( chooseDatabase ); chooseDatabase.AttachEvent( "onchange", "chooseDatabase_onchange" ); GuiButton btnSave = ui.AddButton("btnSave", "Save", "保存改变"); btnSave.AttachEvent("onclick", "btnSave_onclick"); ui.ShowGui = true; } else { ui.ShowGui = false; } } public void setupDatabaseDropdown( GuiComboBox Databases ) { try { if( MyMeta.IsConnected ) { Databases.BindData( MyMeta.Databases ); if( MyMeta.DefaultDatabase != null ) { Databases.SelectedValue = MyMeta.DefaultDatabase.Alias; bindTables( Databases.SelectedValue ); bindViews( Databases.SelectedValue ); } } } catch { } } public void bindTables( string sDatabase ) { int count = 0; GuiListBox lstTables = ui["chooseTables"] as GuiListBox; try { IDatabase db = MyMeta.Databases[sDatabase]; lstTables.BindData( db.Tables ); } catch { } } public void bindViews( string sDatabase ) { int count = 0; GuiListBox lstViews = ui["chooseViews"] as GuiListBox; try { IDatabase db = MyMeta.Databases[sDatabase]; lstViews.BindData( db.Views ); } catch { } } public void chooseDatabase_onchange( GuiComboBox control ) { int count = 0; GuiComboBox cmbDatabases = ui["chooseDatabase"] as GuiComboBox; bindTables( cmbDatabases.SelectedText ); bindViews( cmbDatabases.SelectedText ); } private bool getBool(object valor){ return Boolean.Parse((string) valor); } public void btnSave_onclick(GuiButton btnSave) { RegistryKey reg ; reg = Registry.CurrentUser; reg = reg.CreateSubKey("Software"); reg = reg.CreateSubKey("DDLLY"); reg = reg.CreateSubKey("NHibernateScript"); reg.SetValue("classNamespace", classNamespace.Text); reg.SetValue("Assembly", txtAssembly.Text); reg.SetValue("EnableNullTypes", chkEnableNullTypes.Value.ToString()); reg.SetValue("outputPath", outputPath.Text); reg.SetValue("memberPrefix", memberPrefix.Text); //reg.SetValue("DontCreateFK", chkDontCreateFK.Value.ToString()); reg.SetValue("UseNull", chkUseNull.Value.ToString()); reg.SetValue("EqualsHashCode", chkEqualsHashCode.Value.ToString()); reg.SetValue("ReadOnly", chkReadOnly.Value.ToString()); reg.SetValue("Class", chkClass.Value.ToString()); reg.SetValue("Mapping", chkMapping.Value.ToString()); reg.SetValue("LazyClass", chkLazyClass.Value.ToString()); reg.SetValue("EnableNullTypes", chkEnableNullTypes.Value.ToString()); } }
问题内容: 我正在寻找可以从以下人员获得帮助的编辑器 http://www.hibernate.org/hib_docs/nhibernate/html/mapping.html 内置,并允许以GUI方式简单地编辑XML文件。我意识到这里有CodeSmith和MyGeneration,但据我所知,它们只是一种方式,并且不允许编辑现有的HBM文件。 问题答案: 也许值得看一下Oren Eini的NH
生成类库映射文件optimize:autoload 可以使用下面的指令生成类库映射文件,提高系统自动加载的性能。 >php think optimize:autoload 指令执行成功后,会在rumtime目录下面生成classmap.php文件,生成的类库映射文件会扫描系统目录和应用目录的类库。
本文向大家介绍nhibernate 流利的NHibernate映射,包括了nhibernate 流利的NHibernate映射的使用技巧和注意事项,需要的朋友参考一下 示例 该Fluent NHibernate是一个库,以帮助您在使用C#代码,而不是XML映射的实体映射。Fluent NHibernate使用,fluent pattern并且它基于约定来创建映射,它为Visual Studio工具
本文向大家介绍nhibernate 要映射的模型样本,包括了nhibernate 要映射的模型样本的使用技巧和注意事项,需要的朋友参考一下 示例 NHibernate使用类来映射到表或视图中。Plain Old CLR Object对于持久性类,创建(POCO,有时也称为普通普通CLR对象)是一种很好的做法。POCO的数据可通过标准.NET属性机制访问,从而使内部表示不受公共可见界面的影响。 NH
我正在为我们班做一个项目。需要将DTO映射到实体,反之亦然。我的DTO没有Id字段,转换正在控制器层进行。另外两个类正在扩展我的实体,因此@Superbuilder。 我的转换实体- 但是DTO- 如果你们谁能帮我找到解决办法,我将不胜感激。提前感谢您的时间和回复。 =======我的DTO===== =====我的实体===== } ====ModelMapper的Bean===== =====
快速总结我想要实现的目标。请给出实施或设计建议:) 我有两个表:用户,图像。在UserDO中,我希望保留一组所有用户的图像,以及单个图像,即用户的肖像(在我的示例中,该组将包括肖像): 在ImageDO中,我有一个userid作为外键来记录哪个用户上传了图像。但是它没有布尔值,因为认为一个用户可能会上传许多图像,但只有一个是肖像。 有什么方法可以实现这一点吗?或者我需要维护另一个表(例如,Port
我有以下模式: 项目(ID,名称)项目用户(项目ID,用户ID)用户(名称,ID) 实体如下 显然是一对多。项目可以有多个用户。 现在,我的目标是编写jooq查询,在那里我可以获取已经有相应用户的项目对象。 但是当预期约15时,查询将恢复千分之一的结果
我在Kotlin-vertx项目中配置了Hibernate,我设法设置了所有内容,但当我运行HQL查询时,它会输出: 提前谢了。