/// <summary> /// 根据对象拼Insert语句 /// </summary> /// <typeparam name="T">对象类型</typeparam> /// <param name="graph">对象</param> /// <param name="mapping">映射关系</param> /// <param name="builder">生成Sql语句类型的Builder如TSqlBuilder或PlSqlBuilder</param> /// <param name="ignorProperties">忽略的字段</param> /// <returns>根据传入的对象和对象映射时需要忽略的字段以及类定义上的表名,生成完整的Insert语句</returns> public static string GetInsertSql <T>(T graph, ORMappingItemCollection mapping, ISqlBuilder builder, params string[] ignorProperties) { ExceptionHelper.FalseThrow <ArgumentNullException>(graph != null, "graph"); ExceptionHelper.FalseThrow <ArgumentNullException>(mapping != null, "mapping"); ExceptionHelper.FalseThrow <ArgumentNullException>(builder != null, "builder"); InsertSqlClauseBuilder insertBuilder = GetInsertSqlClauseBuilder(graph, mapping, ignorProperties); return(string.Format("INSERT INTO {0} {1} \r\n SELECT SCOPE_IDENTITY()", mapping.TableName, insertBuilder.ToSqlString(builder))); }
/// <summary> /// 根据对象拼Insert语句时的方法 /// </summary> /// <typeparam name="T">对象类型</typeparam> /// <param name="graph">对象</param> /// <param name="mapping">映射关系</param> /// <param name="ignorProperties">忽略的字段</param> /// <returns>InsertSqlClauseBuilder对象,供拼Insert语句使用</returns> /// <remarks> /// 根据传入的对象和对象映射时需要忽略的字段,返回InsertSqlClauseBuilder对象,以供后续拼Insert语句的字段名称和Values部分 /// <code source="..\Framework\TestProjects\DeluxeWorks.Library.Data.SqlBuilder.Test\ORMappingTest.cs" region="GetInsertSqlClauseBuilder" lang="cs" title="拼Insert语句"/> /// <see cref="MCS.Library.Data.Builder.InsertSqlClauseBuilder"/> /// </remarks> public static InsertSqlClauseBuilder GetInsertSqlClauseBuilder <T>(T graph, ORMappingItemCollection mapping, params string[] ignorProperties) { ExceptionHelper.FalseThrow <ArgumentNullException>(graph != null, "graph"); ExceptionHelper.FalseThrow <ArgumentNullException>(mapping != null, "mapping"); InsertSqlClauseBuilder builder = new InsertSqlClauseBuilder(); FillSqlClauseBuilder(builder, graph, mapping, ClauseBindingFlags.Insert, new DoSqlClauseBuilder <T>(DoInsertUpdateSqlClauseBuilder <T>), ignorProperties); return(builder); }