当前位置: 首页>>代码示例>>C#>>正文


C# IClassMap.GetPropertyMapForColumnMap方法代码示例

本文整理汇总了C#中IClassMap.GetPropertyMapForColumnMap方法的典型用法代码示例。如果您正苦于以下问题:C# IClassMap.GetPropertyMapForColumnMap方法的具体用法?C# IClassMap.GetPropertyMapForColumnMap怎么用?C# IClassMap.GetPropertyMapForColumnMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IClassMap的用法示例。


在下文中一共展示了IClassMap.GetPropertyMapForColumnMap方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateFind

		/// <summary>
		/// Generates the 'find' method.
		/// </summary>
		/// <param name="file">The file.</param>
		/// <param name="classMap">The class map.</param>
		public override void GenerateFind(StreamWriter file, IClassMap classMap)
		{
			ArrayList primaryColumns = classMap.GetTableMap().GetPrimaryKeyColumnMaps();

			StringBuilder whereQuery = new StringBuilder();
			StringBuilder findParams = new StringBuilder();
			bool first = true;

			foreach (IColumnMap primColumn in primaryColumns)
			{
				IPropertyMap propertyMap = classMap.GetPropertyMapForColumnMap(primColumn);

				if (!first)
				{
					whereQuery.Append(", ");
					findParams.Append(", ");
				}

				whereQuery
					.Append('`')
					.Append(primColumn.Name)
					.Append("`='\" + m_state.EscapeString(")
					.Append(ClassUtility.GetParamName(propertyMap))
					.Append(".ToString()) + \"'");

				string paramName = ClassUtility.GetParamName(propertyMap);
				string paramType = ClassUtility.ConvertColumnTypeToCsType(primColumn.DataType);
					
				findParams.Append(paramType + " " + paramName);

				first = false;
			}
			
			string entityClassName = EntityGenerator.GetTypeName(classMap);
			string sqlCommand = "SELECT \" + c_rowFields + \""
				+ " FROM `" + classMap.GetTableMap().Name + "`"
				+ " WHERE " + whereQuery.ToString();

			file.WriteLine("		public virtual " + entityClassName + " Find(" + findParams.ToString() + ")");
			file.WriteLine("		{");
			file.WriteLine("			" + entityClassName + " result = new " + entityClassName + "();");
			file.WriteLine("			string command = \"" + sqlCommand + "\";");
			file.WriteLine();
			file.WriteLine("			m_state.ExecuteQuery(");
			file.WriteLine("				command,");
			file.WriteLine("				CommandBehavior.SingleRow,");
			file.WriteLine("				delegate(MySqlDataReader reader)");
			file.WriteLine("				{");
			file.WriteLine("					if (!reader.Read())");
			file.WriteLine("					{");
			file.WriteLine("						result = null;");
			file.WriteLine("					}");
			file.WriteLine("					else");
			file.WriteLine("					{");
			file.WriteLine("						FillEntityWithRow(ref result, reader);");
			file.WriteLine("					}");
			file.WriteLine("				}");
			file.WriteLine("			);");
			file.WriteLine();
			file.WriteLine("			return result;");
			file.WriteLine("		}");
			file.WriteLine();
		}
开发者ID:Dawn-of-Light,项目名称:Puzzle.NET,代码行数:68,代码来源:MySqlDataAccessObjectGenerator.cs

示例2: GenerateFindMethods

		/// <summary>
		/// Generates all the 'find' methods of this interface.
		/// </summary>
		/// <param name="classMap">The class map.</param>
		/// <param name="file">The file.</param>
		private static void GenerateFindMethods (IClassMap classMap, StreamWriter file)
		{				
			// method name
			file.Write("		" + EntityGenerator.GetTypeName(classMap) + " Find(");
			ArrayList primaryColumns = classMap.GetTableMap().GetPrimaryKeyColumnMaps();

			// method's params
			bool first = true;
			foreach (IColumnMap columnMap in primaryColumns)
			{
				IPropertyMap propertyMap = classMap.GetPropertyMapForColumnMap(columnMap);

				if (!first)
				{
					file.Write(", ");
				}

				// param type and name
				string paramName = ClassUtility.GetParamName(propertyMap);
				string paramType = ClassUtility.ConvertColumnTypeToCsType(columnMap.DataType);
				file.Write(paramType + " " + paramName);
				first = false;

			}
			file.Write(");");

			file.WriteLine();
		}
开发者ID:Dawn-of-Light,项目名称:Puzzle.NET,代码行数:33,代码来源:DataAccessInterfaceGenerator.cs

示例3: GenerateDelete

		/// <summary>
		/// Generates the 'delete' method.
		/// </summary>
		/// <param name="file">The file.</param>
		/// <param name="classMap">The class map.</param>
		public override void GenerateDelete(StreamWriter file, IClassMap classMap)
		{
			ArrayList primaryColumns = classMap.GetTableMap().GetPrimaryKeyColumnMaps();

			bool first = true;
			StringBuilder whereQuery = new StringBuilder(16 * primaryColumns.Count);

			foreach (IColumnMap columnMap in primaryColumns)
			{
				IPropertyMap propertyMap = classMap.GetPropertyMapForColumnMap(columnMap);
				
				if (!first)
				{
					whereQuery.Append("AND ");
				}

				whereQuery
					.Append('`')
					.Append(columnMap.Name)
					.Append("`='\" + m_state.EscapeString(")
					.Append("obj." + propertyMap.Name)
					.Append(".ToString()) + \"'");

				first = false;
			}

			string sqlCommand = "DELETE FROM `" + classMap.GetTableMap().Name + "`"
				+ " WHERE " + whereQuery.ToString();

			file.WriteLine("			m_state.ExecuteNonQuery(");
			file.WriteLine("				\"" + sqlCommand + "\");");
		}
开发者ID:Dawn-of-Light,项目名称:Puzzle.NET,代码行数:37,代码来源:MySqlDataAccessObjectGenerator.cs


注:本文中的IClassMap.GetPropertyMapForColumnMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。