Esempio n. 1
0
 public object Insert(T m)
 {
     try
     {
         StringBuilder fields = new StringBuilder();
         StringBuilder values = new StringBuilder();
         Guid          gd = Guid.Empty;
         string        tp = string.Empty; object o = null;
         var           getmth = GetMethod;
         foreach (var n in Fields.Values)
         {
             if (n.IsExcludeColumn || n.IsExcludeDelegate)
             {
                 continue;
             }
             if (n.IsKey)
             {
                 if (n.FieldType.Equals(typeof(Guid)))
                 {
                     gd = Guid.NewGuid();
                     fields.Append(Quote(n.Name) + ",");
                     tp = db.ParStr(n.Name);
                     values.Append(tp + ",");
                     ps.Add(db.Cp(tp, gd));
                 }
                 continue;
             }
             o = getmth.Invoke(m, n.Name.ToLower());
             if (o == null)
             {
                 continue;
             }
             fields.Append(Quote(n.Name) + ",");
             tp = db.ParStr(n.Name);
             values.Append(tp + ",");
             ps.Add(db.Cp(tp, o));
         }
         if (fields.Length > 0)
         {
             fields.Length--;
         }
         if (values.Length > 0)
         {
             values.Length--;
         }
         tp = "INSERT INTO " + TableName + "(" + fields.ToString() + ")VALUES(" + values.ToString() + ") " + (gd != Guid.Empty?string.Empty:db.GetIdStr);
         if (OrmGlobal.isrecord)
         {
             Record(tp);
         }
         object a = db.ExectueScalar(tp, ps, false);
         Clear();
         return(gd != Guid.Empty?gd:a);
     }
     catch
     {
         OrmGlobal.DoErr(sqlinfo.ToString()); throw;
     }
 }