private void CheckAuthorOrdinals(SqlCeResultSet results)
 {
     if (m_authorOrdinals.Count == 0)
     {
         for (int i = 0; i < results.FieldCount; i++)
         {
             m_authorOrdinals.Add(results.GetName(i), i);
         }
     }
 }
Example #2
0
        private List <object> WalkObject(Object Input, ShipmentContext context, SqlCeResultSet resultSet)
        {
            bool firstOccurrence;

            gen.GetId(Input, out firstOccurrence);
            if (!firstOccurrence)
            {
                return(null);
            }

            CachedTableInfo metadata = new CachedTableInfo(Input.GetType().Name, context, resultSet);

            List <string>        processedFields = new List <string>();
            List <object>        keys            = new List <object>();
            SqlCeUpdatableRecord r = resultSet.CreateRecord();

            // Match the database with memory object.
            for (int i = 0; i < resultSet.FieldCount; i++)
            {
                if (!metadata.IsFieldKey(r.GetName(i)))
                {
                    string       fieldName = resultSet.GetName(i);
                    PropertyInfo fi        = Input.GetType().GetProperty(fieldName);
                    if (fi != null)
                    {
                        r[i] = fi.GetValue(Input, null);
                        processedFields.Add(fieldName);
                    }
                    else
                    {
                        throw new InvalidOperationException(string.Format("Field {0} was not found in the class {1}",
                                                                          fi.Name, Input.GetType().Name));
                    }
                }
            }
            resultSet.Insert(r, DbInsertOptions.PositionOnInsertedRow);
            foreach (var item in metadata.Keys)
            {
                keys.Add(r[item.Name]);
            }

            // keys now contain assigned autoincrement fields.
            return(keys);
        }
 private void CheckOrdinals(SqlCeResultSet results)
 {
     if (m_bookOrdinals.Count == 0)
     {
         for (int i = 0; i < results.FieldCount; i++)
         {
             m_bookOrdinals.Add(results.GetName(i), i);
         }
     }
 }