private UIDRoutineParameter[] GetRoutineParameters(zetesDataContext db)
 {
     IEnumerable<UIDRoutineParameter> parameters =
         db.UIDRoutineParameters;
     return parameters.ToArray();
 }
        private void CreatePartialMethods()
        {
            using (zetesDataContext db = new zetesDataContext(BuildConnectString()))
            {
                IEnumerable<UIDRoutine> routines = GetRoutines(db);
                UIDRoutineParameter[] allRoutineParameters = GetRoutineParameters(db);
                foreach (UIDRoutine routine in routines)
                {
                    ChangeFaultedObjects(routine);

                    StringBuilder sb = new StringBuilder(512);
                    UIDRoutineParameter[] routineParameters =
                        allRoutineParameters
                        .Where(p => p.routine_name == routine.routine_name)
                        .OrderBy(p => p.ORDINAL_POSITION)
                        .ToArray();

                    // Header
                    AddLine(sb, string.Format("partial void {0}({1} instance) {{", routine.PartialMethodName, routine.relation));
                    AddLine2(sb, "int rc;");
                    AddLine2(sb, "string errorinfo = null;");
                    foreach (UIDRoutineParameter routineParameter in routineParameters)
                    {
                        if (routineParameter.CS_DECLARATION != null)
                        {
                            AddLine2(sb, routineParameter.CS_DECLARATION);
                        }
                    }
                    sb.AppendLine();
                    AddLine2(sb, string.Format("rc = this.{0}(", routine.routine_name));
                    for (int i = 0; i < routineParameters.Count(); i++)
                    {
                        UIDRoutineParameter routineParameter = routineParameters[i];
                        AddLine3(sb, string.Concat(routineParameter.CS_PARAMETER_DESCR, i == routineParameters.Count() - 1 ? ");" : ","));
                    }
                    foreach (UIDRoutineParameter routineParameter in routineParameters)
                    {
                        if (routineParameter.CS_AFTER_CALL != null)
                        {
                            AddLine2(sb, routineParameter.CS_AFTER_CALL);
                        }
                    }
                    AddLine2(sb, "if (rc != 0) {");
                    AddLine2(sb, "  throw new Exception(errorinfo != String.Empty ? errorinfo : string.Format(UnknownError, rc));");
                    AddLine2(sb, "}");
                    AddLine(sb, "}");
 
                    Console.WriteLine(sb.ToString());
                }
            }
        }
        private IEnumerable<UIDRoutine> GetRoutines(zetesDataContext db)
        {
            string[] relations = {};

            IEnumerable<UIDRoutine> routines =
                db.UIDRoutines
                .Where(r => !relations.Contains(r.relation))
                .OrderBy(r => r.relation)
                .ThenBy(r => r.PartialMethodName);
            return routines.ToArray();
        }