コード例 #1
0
        public T First <T>(DbSeekOptions option, string seekField, object seekValue)
            where T : class
        {
            var entityName = m_entities.GetNameForType(typeof(T));

            return((T)Seek(entityName, typeof(T), option, seekField, seekValue));
        }
コード例 #2
0
        private object Seek(string entityName, Type objectType, DbSeekOptions option, string seekField, object seekValue)
        {
            UpdateIndexCacheForType(entityName);

            var          connection     = GetConnection(false);
            var          fillReferences = false;
            SqlCeCommand command        = null;

            if (UseCommandCache)
            {
                Monitor.Enter(CommandCache);
            }

            try
            {
                ReferenceAttribute[] referenceFields = null;
                bool tableDirect;

                CheckOrdinals(entityName);
                CheckPrimaryKeyIndex(entityName);

                command = GetSelectCommand <SqlCeCommand, SqlCeParameter>(entityName,
                                                                          new FilterCondition[] { new FilterCondition(seekField, seekValue, FilterCondition.FilterOperator.Equals) },
                                                                          out tableDirect);
                command.Connection  = connection as SqlCeConnection;
                command.Transaction = CurrentTransaction as SqlCeTransaction;

                using (var results = command.ExecuteReader())
                {
                    bool found = results.Seek(option, seekValue);

                    if (!found)
                    {
                        return(null);
                    }

                    results.Read();

                    bool   fieldsSet;
                    object item = CreateEntityInstance(entityName, objectType, Entities[entityName].Fields, results, out fieldsSet);

                    if (!fieldsSet)
                    {
                        // fill in the entity field values
                        PopulateFields(entityName, Entities[entityName].Fields, results, item, fillReferences);
                    }

                    // autofill references if desired
                    if ((fillReferences) && (referenceFields.Length > 0))
                    {
                        FillReferences(item, null, referenceFields, false);
                    }

                    return(item);
                }
            }
            finally
            {
                if ((!UseCommandCache) && (command != null))
                {
                    command.Dispose();
                }

                if (UseCommandCache)
                {
                    Monitor.Exit(CommandCache);
                }

                FlushReferenceTableCache();
                DoneWithConnection(connection, false);
            }
        }
コード例 #3
0
 public DynamicEntity First(string entityName, DbSeekOptions option, string seekField, object seekValue)
 {
     return((DynamicEntity)Seek(entityName, typeof(DynamicEntity), option, seekField, seekValue));
 }